2021-08-04 20:08:33 +02:00
|
|
|
import fs from 'fs'
|
2021-08-05 23:27:11 +02:00
|
|
|
import { njkRenderer } from './njkRenderer.js'
|
2021-08-04 20:08:33 +02:00
|
|
|
|
|
|
|
export function requestHandler(req, res, Config) {
|
2021-08-05 23:27:11 +02:00
|
|
|
if (fs.existsSync(`./${Config.contentDir}/pages/${req.path}.njk`))
|
|
|
|
return res.send(njkRenderer(`./${Config.contentDir}/pages/${req.path}.njk`))
|
2021-08-04 20:08:33 +02:00
|
|
|
|
2021-08-05 23:27:11 +02:00
|
|
|
if (fs.existsSync(`./${Config.contentDir}/pages/${req.path}/index.njk`))
|
|
|
|
return res.send(njkRenderer(`./${Config.contentDir}/pages/${req.path}/index.njk`))
|
2021-08-04 20:08:33 +02:00
|
|
|
|
|
|
|
return res.status(404).render('errors/404.njk', context)
|
|
|
|
}
|