From b18dd29fa0a5f9d4f7260b34e0eb935755867217 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Tue, 14 Jan 2020 22:21:24 -0500 Subject: [PATCH] feat: browse page by ID --- server/app/data.yml | 2 ++ server/controllers/common.js | 33 +++++++++++++++++++++++++++++++++ server/core/servers.js | 2 +- server/master.js | 7 ++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/server/app/data.yml b/server/app/data.yml index f0dfbf47..2baef4d4 100644 --- a/server/app/data.yml +++ b/server/app/data.yml @@ -16,6 +16,8 @@ defaults: db: wiki ssl: false storage: ./db.sqlite + sslOptions: + auto: true ssl: enabled: false pool: diff --git a/server/controllers/common.js b/server/controllers/common.js index 4951d23e..23224554 100644 --- a/server/controllers/common.js +++ b/server/controllers/common.js @@ -129,6 +129,39 @@ router.get(['/h', '/h/*'], async (req, res, next) => { } }) +/** + * Page ID redirection + */ +router.get(['/i', '/i/:id'], async (req, res, next) => { + const pageId = _.toSafeInteger(req.params.id) + if (pageId <= 0) { + return res.redirect('/') + } + + const page = await WIKI.models.pages.query().column(['path', 'localeCode', 'isPrivate', 'privateNS']).findById(pageId) + if (!page) { + _.set(res.locals, 'pageMeta.title', 'Page Not Found') + return res.status(404).render('notfound', { action: 'view' }) + } + + if (!WIKI.auth.checkAccess(req.user, ['read:pages'], { + locale: page.localeCode, + path: page.path, + private: page.isPrivate, + privateNS: page.privateNS, + explicitLocale: false + })) { + _.set(res.locals, 'pageMeta.title', 'Unauthorized') + return res.render('unauthorized', { action: 'view' }) + } + + if (WIKI.config.lang.namespacing) { + return res.redirect(`/${page.localeCode}/${page.path}`) + } else { + return res.redirect(`/${page.path}`) + } +}) + /** * Profile */ diff --git a/server/core/servers.js b/server/core/servers.js index d2c5f4da..0cca5315 100644 --- a/server/core/servers.js +++ b/server/core/servers.js @@ -136,7 +136,7 @@ module.exports = { * Close all active connections */ closeConnections () { - for (const conn of this.connections) { + for (const conn of this.connections.values()) { conn.destroy() } this.connections.clear() diff --git a/server/master.js b/server/master.js index 1369bdf6..604264bb 100644 --- a/server/master.js +++ b/server/master.js @@ -80,6 +80,12 @@ module.exports = async () => { app.use(WIKI.auth.passport.initialize()) app.use(WIKI.auth.authenticate) + // ---------------------------------------- + // GraphQL Server + // ---------------------------------------- + + await WIKI.servers.startGraphQL() + // ---------------------------------------- // SEO // ---------------------------------------- @@ -173,7 +179,6 @@ module.exports = async () => { // Start HTTP Server(s) // ---------------------------------------- - await WIKI.servers.startGraphQL() await WIKI.servers.startHTTP() if (WIKI.config.ssl.enabled === true || WIKI.config.ssl.enabled === 'true' || WIKI.config.ssl.enabled === 1 || WIKI.config.ssl.enabled === '1') {