Commit b18dd29f authored by NGPixel's avatar NGPixel

feat: browse page by ID

parent e836a497
...@@ -16,6 +16,8 @@ defaults: ...@@ -16,6 +16,8 @@ defaults:
db: wiki db: wiki
ssl: false ssl: false
storage: ./db.sqlite storage: ./db.sqlite
sslOptions:
auto: true
ssl: ssl:
enabled: false enabled: false
pool: pool:
......
...@@ -130,6 +130,39 @@ router.get(['/h', '/h/*'], async (req, res, next) => { ...@@ -130,6 +130,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 * Profile
*/ */
router.get(['/p', '/p/*'], (req, res, next) => { router.get(['/p', '/p/*'], (req, res, next) => {
......
...@@ -136,7 +136,7 @@ module.exports = { ...@@ -136,7 +136,7 @@ module.exports = {
* Close all active connections * Close all active connections
*/ */
closeConnections () { closeConnections () {
for (const conn of this.connections) { for (const conn of this.connections.values()) {
conn.destroy() conn.destroy()
} }
this.connections.clear() this.connections.clear()
......
...@@ -81,6 +81,12 @@ module.exports = async () => { ...@@ -81,6 +81,12 @@ module.exports = async () => {
app.use(WIKI.auth.authenticate) app.use(WIKI.auth.authenticate)
// ---------------------------------------- // ----------------------------------------
// GraphQL Server
// ----------------------------------------
await WIKI.servers.startGraphQL()
// ----------------------------------------
// SEO // SEO
// ---------------------------------------- // ----------------------------------------
...@@ -173,7 +179,6 @@ module.exports = async () => { ...@@ -173,7 +179,6 @@ module.exports = async () => {
// Start HTTP Server(s) // Start HTTP Server(s)
// ---------------------------------------- // ----------------------------------------
await WIKI.servers.startGraphQL()
await WIKI.servers.startHTTP() 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') { if (WIKI.config.ssl.enabled === true || WIKI.config.ssl.enabled === 'true' || WIKI.config.ssl.enabled === 1 || WIKI.config.ssl.enabled === '1') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment