15 lines
477 B
JavaScript
15 lines
477 B
JavaScript
|
import fs from 'fs'
|
||
|
|
||
|
export function requestHandler(req, res, Config) {
|
||
|
const context = {
|
||
|
serverName: Config.serverName
|
||
|
}
|
||
|
|
||
|
if (fs.existsSync(`./${Config.contentDir}/pages/${req.path}.njk`, context))
|
||
|
return res.render(`pages/${req.path}.njk`)
|
||
|
|
||
|
if (fs.existsSync(`./${Config.contentDir}/pages/${req.path}/index.njk`, context))
|
||
|
return res.render(`pages/${req.path}/index.njk`)
|
||
|
|
||
|
return res.status(404).render('errors/404.njk', context)
|
||
|
}
|