koa-plugins/index.js
2020-03-01 19:52:04 +01:00

35 lines
No EOL
774 B
JavaScript

const PORT = 80;
module.exports = (PORT)=>{
console.log("[INFO] Starting...");
const Koa = require("koa");
const app = new Koa;
const Hooks = require("./hooks");
const hooks = new Hooks;
const isElevated = require('is-elevated');
hooks.registerPlugins(app);
app.use(async ctx => {
await hooks.runPlugins(ctx);
});
console.log("Plugins loaded, starting webserver");
(async()=>{
if(!await isElevated() && PORT < 1024){
console.error("Ports lower than 1024 requires elevated shell.");
process.exit(1);
}
app.listen(PORT, ()=>{
console.log("Web ready");
})
})();
}
if(require.main === module){
module.exports(PORT);
}