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")
|
|
|
|
|
|
|
|
const pinski = new Pinski({
|
2020-04-14 14:03:38 +00:00
|
|
|
port: +process.env.PORT || constants.port,
|
2020-04-17 12:18:58 +00:00
|
|
|
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-01-12 12:50:21 +00:00
|
|
|
})
|
|
|
|
|
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
|
|
|
|
|
2020-02-18 04:06:11 +00:00
|
|
|
// 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-09 11:37:56 +00:00
|
|
|
for (const theme of constants.themes) {
|
|
|
|
pinski.addRoute(`/static/css/${theme.file}.css`, `sass/${theme.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) {
|
|
|
|
console.log("Assistant API enabled")
|
|
|
|
pinski.addAPIDir("assistant_api")
|
|
|
|
}
|
|
|
|
|
2020-01-12 12:50:21 +00:00
|
|
|
pinski.startServer()
|
|
|
|
|
|
|
|
require("pinski/plugins").setInstance(pinski)
|
|
|
|
|
|
|
|
Object.assign(passthrough, pinski.getExports())
|
2020-01-18 15:38:14 +00:00
|
|
|
|
|
|
|
console.log("Server started")
|
2020-04-04 12:20:12 +00:00
|
|
|
|
|
|
|
if (process.stdin.isTTY || process.argv.includes("--enable-repl")) {
|
|
|
|
require("./repl")
|
|
|
|
}
|
2020-01-12 12:50:21 +00:00
|
|
|
})
|