1
0
This repository has been archived on 2026-01-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
secret-sender-old-1/src/core/server.js
2024-10-27 22:12:57 +01:00

64 lines
1.6 KiB
JavaScript

import fs from "fs"
import express from "express"
import http from "http"
import https from "https"
import i18n from "./i18n.js"
import routes from "./routes.js"
const defaulthandler = (req, res, next) => {
res.redirect("/")
}
const pug = (res, file, value, allowcache) => {
//app.srv.cache(res,allowcache!=false)
res.setHeader("X-Frame-Options", "sameorigin")
res.setHeader("X-XSS-Protection", "1; mode=block")
res.render(file, value)
}
/*
const getremoteip = (req) => {
return req.ip
}
*/
const start = (srvConfig) => {
const app = express()
const router = express.Router()
router.use(express.json())
router.pug = pug
// router.i18n = i18n
app.locals.i18n = i18n
routes.load(router, srvConfig.features)
app.disable("x-powered-by")
app.set('trust proxy', true)
app.set("views", __dirname + "/pug")
app.set("view engine", "pug")
app.use(router)
app.use(express.static(__dirname + "/html", {maxAge: 86400000000}))
app.use(defaulthandler)
if(srvConfig.http) {
const srv = http.createServer({}, app)
srv.listen(srvConfig.http.port, '0.0.0.0')
console.log("Listen http " + srvConfig.http.port + " : " + JSON.stringify(srvConfig.features))
}
if(srvConfig.https && fs.existsSync(srvConfig.https.cert) && fs.existsSync(srvConfig.https.key)) {
const sslsrv = https.createServer({
cert: fs.readFileSync(srvConfig.https.cert),
key: fs.readFileSync(srvConfig.https.key),
}, app)
sslsrv.listen(srvConfig.https.port, '0.0.0.0')
console.log("Listen https " + srvConfig.https.port + " : " + JSON.stringify(srvConfig.features))
}
}
export default {
start,
}