qwik-cms/index.js

56 lines
1.0 KiB
JavaScript
Raw Normal View History

import fs from 'fs'
2021-07-27 19:24:51 +02:00
import express from 'express'
2021-07-27 19:24:51 +02:00
import njk from 'nunjucks'
2021-08-04 20:08:33 +02:00
import njkMarkdown from 'nunjucks-markdown'
import marked from 'marked'
2021-07-27 19:24:51 +02:00
import { requestHandler } from './libs/requestHandler.js'
import { markedRenderer } from './libs/markedRenderer.js'
2021-07-27 19:24:51 +02:00
2021-07-27 21:04:57 +02:00
// Load in config
2021-08-04 20:08:33 +02:00
const ConfigFile = fs.readFileSync('./config.json')
2021-07-27 19:24:51 +02:00
const Config = JSON.parse(ConfigFile)
const Server = express()
// Some config
2021-07-27 19:24:51 +02:00
Server.use('/assets', express.static(Config.assetsDir))
2021-08-04 17:48:11 +02:00
const njkEnv = njk.configure(
2021-07-27 19:24:51 +02:00
Config.contentDir,
{
autoescape: true,
2021-07-27 21:57:48 +02:00
watch: true,
trimBlocks: true,
lstripBlocks: true,
2021-07-27 19:24:51 +02:00
express: Server
}
)
2021-08-07 10:16:13 +02:00
marked.use({
gfm: true,
renderer: markedRenderer
2021-08-04 22:52:49 +02:00
})
2021-08-04 20:08:33 +02:00
njkMarkdown.register(njkEnv, marked)
2021-07-27 19:24:51 +02:00
2021-07-27 21:04:57 +02:00
// Send all requests to the requestHandler.
Server.get('*', (req, res) => requestHandler(req, res, Config))
// Start the server
2021-07-27 19:24:51 +02:00
Server.listen(
Config.serverPort,
() => {
console.log(`Started server on ${Config.serverPort}.`)
}
)