qwik-cms/libs/requestHandler.js

12 lines
507 B
JavaScript
Raw Normal View History

2021-08-04 20:08:33 +02:00
import fs from 'fs'
import { njkRenderer } from './njkRenderer.js'
2021-08-04 20:08:33 +02:00
export function requestHandler(req, res, Config) {
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
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)
}