2021-08-05 23:27:11 +02:00
|
|
|
import fs from 'fs'
|
2021-07-27 19:24:51 +02:00
|
|
|
import express from 'express'
|
2021-08-05 23:27:11 +02:00
|
|
|
|
2021-07-27 19:24:51 +02:00
|
|
|
import njk from 'nunjucks'
|
|
|
|
|
2021-08-05 23:27:11 +02:00
|
|
|
import { requestHandler } from './libs/requestHandler.js'
|
2021-08-09 16:55:53 +02:00
|
|
|
import { utils } from './libs/utils/utils.js'
|
|
|
|
import { nunjacksConfig } from './libs/nunjucksConfig.js'
|
2021-07-27 19:24:51 +02:00
|
|
|
|
2021-07-27 21:04:57 +02:00
|
|
|
|
2021-08-05 23:27:11 +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)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-07 10:46:48 +02:00
|
|
|
// Create a server object
|
2021-07-27 19:24:51 +02:00
|
|
|
const Server = express()
|
|
|
|
|
2021-08-05 23:27:11 +02:00
|
|
|
|
|
|
|
|
2021-08-07 10:46:48 +02:00
|
|
|
// Configure the assets directory
|
2021-07-27 19:24:51 +02:00
|
|
|
Server.use('/assets', express.static(Config.assetsDir))
|
|
|
|
|
2021-08-09 16:55:53 +02:00
|
|
|
// Configure nunjacks
|
|
|
|
nunjacksConfig(njk, Server, Config)
|
2021-08-04 22:52:49 +02:00
|
|
|
|
2021-08-09 16:55:53 +02:00
|
|
|
// Generate utils
|
|
|
|
utils.generate()
|
2021-07-27 19:24:51 +02:00
|
|
|
|
|
|
|
|
2021-07-27 21:04:57 +02:00
|
|
|
|
2021-08-05 23:27:11 +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}.`)
|
|
|
|
}
|
|
|
|
)
|