qwik-cms/index.js
2021-08-09 16:55:53 +02:00

44 lines
848 B
JavaScript

import fs from 'fs'
import express from 'express'
import njk from 'nunjucks'
import { requestHandler } from './libs/requestHandler.js'
import { utils } from './libs/utils/utils.js'
import { nunjacksConfig } from './libs/nunjucksConfig.js'
// Load in config
const ConfigFile = fs.readFileSync('./config.json')
const Config = JSON.parse(ConfigFile)
// Create a server object
const Server = express()
// Configure the assets directory
Server.use('/assets', express.static(Config.assetsDir))
// Configure nunjacks
nunjacksConfig(njk, Server, Config)
// Generate utils
utils.generate()
// Send all requests to the requestHandler.
Server.get('*', (req, res) => requestHandler(req, res, Config))
// Start the server
Server.listen(
Config.serverPort,
() => {
console.log(`Started server on ${Config.serverPort}.`)
}
)