forked from qwik/qwik-site
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
import fs from 'fs'
|
|
import { exec } from 'child_process'
|
|
|
|
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'
|
|
import { generateSiteMap } from './libs/utils/siteMap.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))
|
|
|
|
// 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!")
|
|
})
|
|
|
|
|
|
|
|
// Start the server
|
|
Server.listen(
|
|
Config.serverPort,
|
|
() => {
|
|
console.log(`Started server on ${Config.serverPort}.`)
|
|
}
|
|
) |