Skip to content

Commit

Permalink
webservice: allow loading views from any directory
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Apr 15, 2024
1 parent 03087ff commit 6e4e125
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
File renamed without changes.
3 changes: 1 addition & 2 deletions db-tabulator/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { argv, bot, emailOnError, log } from "../botbase";
import { closeTunnels, writeFile } from "../utils";
import { writeFile } from "../utils";
import { checkShutoff, FAKE_OUTPUT_FILE, fetchQueries, processQueries, metadataStore } from "./app";

/**
Expand Down Expand Up @@ -53,5 +53,4 @@ import { checkShutoff, FAKE_OUTPUT_FILE, fetchQueries, processQueries, metadataS

await processQueries(queries);

closeTunnels();
})().catch(e => emailOnError(e, 'db-tabulator'));
2 changes: 1 addition & 1 deletion db-tabulator/web-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ router.get('/stream', async (req, res) => {

router.get('/', async function (req, res, next) {
const {page} = req.query as Record<string, string>;
res.status(200).render('database-report', { page });
res.status(200).render( 'db-tabulator/database-report', { page });
});

async function getLastNonBotRevId(page: string) {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions most-gans/web-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const db = new toolsdb('goodarticles_p', {
router.get('/', async function (req, res) {
if (!req.query.user) {
// Landing page
res.render('gans-landing');
res.render('most-gans/gans-landing');
return;
}
const {user} = req.query;
Expand All @@ -25,7 +25,7 @@ router.get('/', async function (req, res) {
ORDER BY date DESC
`, [user]);

res.render('gans', {
res.render('most-gans/gans', {
user,
dbresult: dbresult.map(row => ({ article: row.article, date: new bot.date(row.date).format('YYYY-MM-DD') }))
});
Expand All @@ -37,7 +37,7 @@ router.get('/credit/:article', async function (req, res) {
if (req.query.raw) {
return res.type('text').send(result?.[0]?.nominator || '<Unknown>');
}
res.render('oneline', {
res.render('webservice/views/oneline', {
text: result?.[0]?.nominator
? `The nominator of "${article}" is ${result[0].nominator}`
: `Some error occurred.`
Expand Down
5 changes: 3 additions & 2 deletions webservice/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import { registerRoutes } from "./route-registry";
const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('views', path.join(__dirname, '../../SDZeroBot'));
app.set('view engine', 'hbs');
app.set('view options', { layout: 'webservice/views/layout' });
hbs.registerHelper('wikilink', (pageName, displayName) => {
return `<a href="https://en.wikipedia.org/wiki/${Mwn.util.wikiUrlencode(pageName)}" title="${pageName.replace(/"/g, '&#34;')}">${typeof displayName === 'string' ? displayName : pageName}</a>`;
});
Expand Down Expand Up @@ -62,7 +63,7 @@ app.use(function (err, req, res, next) {

// render the error page
res.status(err.status || 500);
res.render('error');
res.render('webservice/views/error');
});

export default app;
2 changes: 1 addition & 1 deletion webservice/routes/articlesearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ router.get('/', async (req, res, next) => {
pages[i].excerpt = pElement ? pElement.innerHTML : '[Not found]';
}

res.render('articlesearch', {
res.render('webservice/views/articlesearch', {
query: req.query.query,
data: pages,
});
Expand Down
2 changes: 1 addition & 1 deletion webservice/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as express from "express";
const router = express.Router();

router.get('/', (req, res, next) => {
res.render('index', { title: 'SDZeroBot' });
res.render('webservice/views/index', { title: 'SDZeroBot' });
});

router.get('/ping', (req, res, next) => {
Expand Down

0 comments on commit 6e4e125

Please sign in to comment.