bibliogram/src/site/server.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-01-12 12:50:21 +00:00
const {Pinski} = require("pinski")
const {subdirs} = require("node-dir")
2020-02-02 15:09:40 +00:00
const constants = require("../lib/constants")
2020-01-12 12:50:21 +00:00
const passthrough = require("./passthrough")
2020-05-30 11:07:32 +00:00
const deniedFeatures = [
"accelerometer", "ambient-light-sensor", "battery", "camera", "display-capture", "document-domain", "geolocation", "gyroscope",
"magnetometer", "microphone", "midi", "payment", "publickey-credentials-get", "sync-xhr", "usb", "xr-spatial-tracking"
]
2020-01-12 12:50:21 +00:00
const pinski = new Pinski({
2020-04-14 14:03:38 +00:00
port: +process.env.PORT || constants.port,
ip: constants.bind_ip,
2020-02-16 05:38:52 +00:00
relativeRoot: __dirname,
basicCacheControl: {
exts: ["ttf", "woff2", "png", "jpg", "jpeg", "svg", "gif", "webmanifest", "ico"],
seconds: 604800
},
2020-05-30 11:07:32 +00:00
globalHeaders: {
"Content-Security-Policy": "default-src 'self'; frame-ancestors 'none'; block-all-mixed-content",
"Feature-Policy": deniedFeatures.map(feature => `${feature} 'none'`).join("; "),
2020-05-30 11:21:09 +00:00
"Referrer-Policy": "strict-origin",
2020-05-30 11:07:32 +00:00
"X-Content-Type-Options": "nosniff"
2020-06-19 05:45:51 +00:00
},
onionLocation: constants.onion_location
2020-01-12 12:50:21 +00:00
})
2020-06-20 16:09:36 +00:00
pinski.startServer()
2020-02-02 15:09:40 +00:00
subdirs("pug", async (err, dirs) => {
2020-01-12 12:50:21 +00:00
if (err) throw err
// need to check for and run db upgrades before anything starts using it
await require("../lib/utils/upgradedb")()
2020-02-18 08:03:46 +00:00
pinski.setNotFoundTarget("/404")
2020-05-10 11:58:05 +00:00
Object.assign(pinski.pugDefaultLocals, {constants})
for (const file of constants.themes.collatedFiles) {
pinski.addRoute(`/static/css/${file}.css`, `sass/${file}.sass`, "sass")
}
2020-05-04 14:02:35 +00:00
pinski.addRoute("/settings", "pug/settings.pug", "pug")
2020-01-12 12:50:21 +00:00
pinski.addPugDir("pug", dirs)
2020-05-09 09:34:00 +00:00
pinski.addSassDir("sass", ["sass/includes", "sass/themes"])
2020-05-04 11:50:54 +00:00
pinski.addStaticHashTableDir("html/static/js")
2020-02-02 11:43:56 +00:00
pinski.muteLogsStartingWith("/imageproxy")
pinski.muteLogsStartingWith("/videoproxy")
pinski.muteLogsStartingWith("/static")
2020-02-02 15:09:40 +00:00
2020-04-22 11:59:45 +00:00
for (const route of constants.additional_routes) {
pinski.addRoute(route.web, route.local, route.type)
}
2020-02-02 15:09:40 +00:00
if (constants.tor.enabled) {
await require("../lib/utils/tor") // make sure tor state is known before going further
}
2020-02-18 00:39:20 +00:00
pinski.addAPIDir("api")
2020-04-12 14:52:04 +00:00
if (constants.as_assistant.enabled) {
2020-06-01 14:55:19 +00:00
console.log("[.] Assistant API enabled")
2020-04-12 14:52:04 +00:00
pinski.addAPIDir("assistant_api")
}
2020-01-12 12:50:21 +00:00
require("pinski/plugins").setInstance(pinski)
Object.assign(passthrough, pinski.getExports())
2020-01-18 15:38:14 +00:00
2020-05-29 08:45:34 +00:00
console.log("[.] Server started")
if (process.stdin.isTTY || process.argv.includes("--enable-repl")) {
2020-06-01 14:55:19 +00:00
pinski.waitForFirstCompile().then(() => {
require("./repl")
})
}
2020-01-12 12:50:21 +00:00
})
2020-06-20 16:09:36 +00:00
module.exports = pinski