qwik-site/index.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-08-09 17:44:53 +02:00
import fs from 'fs'
2021-08-10 22:03:06 +02:00
import { exec } from 'child_process'
2021-08-09 17:44:53 +02:00
2021-08-10 22:03:06 +02:00
import express from 'express'
2021-08-09 17:44:53 +02:00
import njk from 'nunjucks'
import { requestHandler } from './libs/requestHandler.js'
import { utils } from './libs/utils/utils.js'
import { nunjacksConfig } from './libs/nunjucksConfig.js'
2021-08-10 22:03:06 +02:00
import { generateSiteMap } from './libs/utils/siteMap.js'
2021-08-09 17:44:53 +02:00
// 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))
2021-08-10 22:03:06 +02:00
// Handle events from gitea.
Server.post('/gitea/pushEvent', (req, res) => {
console.log("Received gitea push event; pulling from gitea and regenerating site map...")
exec("git pull")
generateSiteMap(Config)
res.status(200).send('OK!')
console.log("Done!")
})
2021-08-09 17:44:53 +02:00
// Start the server
2021-08-09 17:44:53 +02:00
Server.listen(
Config.serverPort,
() => {
console.log(`Started server on ${Config.serverPort}.`)
}
)