handle db page not found improved
This commit is contained in:
1 parent
cbc00bee03
commit
85968e0609
2 files changed
+9
-3
No files matched your search
+2
-2
@@ -2,7 +2,7 @@ const {renderPage} = require('../render/page')
|
|||||||
const {get} = require('koa-route')
|
const {get} = require('koa-route')
|
||||||
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function (handleNotFound) {
|
||||||
return get('*', async ctx => {
|
return get('*', async ctx => {
|
||||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||||
const body = await renderPage(path)
|
const body = await renderPage(path)
|
||||||
@@ -10,7 +10,7 @@ module.exports = function () {
|
|||||||
ctx.type = 'text/html'
|
ctx.type = 'text/html'
|
||||||
ctx.body = body
|
ctx.body = body
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404
|
await handleNotFound(ctx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+7
-1
@@ -33,6 +33,12 @@ const dirPublic = path.join(__dirname, '../public')
|
|||||||
|
|
||||||
handlebars.registerHelper('raw-helper', options => options.fn())
|
handlebars.registerHelper('raw-helper', options => options.fn())
|
||||||
|
|
||||||
|
function notFound() {
|
||||||
|
return async ctx => {
|
||||||
|
ctx.status = 404
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function (config) {
|
export default function (config) {
|
||||||
const $ = convert
|
const $ = convert
|
||||||
|
|
||||||
@@ -77,7 +83,7 @@ export default function (config) {
|
|||||||
server.use(documents.getDocuments())
|
server.use(documents.getDocuments())
|
||||||
server.use(document.getDocument())
|
server.use(document.getDocument())
|
||||||
server.use(schedule.getSchedule())
|
server.use(schedule.getSchedule())
|
||||||
server.use(pages())
|
server.use(pages(notFound()))
|
||||||
|
|
||||||
return createServer(server.callback())
|
return createServer(server.callback())
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user