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-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-01-12 12:50:21 +00:00
|
|
|
pinski.addRoute("/static/css/main.css", "sass/main.sass", "sass")
|
|
|
|
pinski.addPugDir("pug", dirs)
|
|
|
|
pinski.addAPIDir("html/static/js/templates/api")
|
|
|
|
pinski.addSassDir("sass")
|
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
|
|
|
|
|
|
|
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
|
|
|
})
|