-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·55 lines (40 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
const config = require("./config.json");
const IP = require("os").networkInterfaces().wlan0[0].address;
const koa = require("koa");
const hbs = require("koa-hbs");
const serve = require("koa-static");
const app = koa();
// socket stuff
const KoaSocket = require("koa-socket");
const io = new KoaSocket();
io.attach(app);
exports.app = app;
// for all socket interations
require("./controllers/sockets");
// misc handlebars helpers
require("./helpers/handlebars");
// statically serve assets
app.use(serve(`${__dirname}`));
// load up the handlebars middlewear
app.use(hbs.middleware({
viewPath: `${__dirname}/views`,
layoutsPath: `${__dirname}/views/layouts`,
partialsPath: `${__dirname}/views/partials`,
defaultLayout: "main"
}));
app.use(function* error(next) {
try {
yield next;
} catch (err) {
this.status = err.status || 500;
this.body = err.message;
this.app.emit("error", err, this);
}
});
require("./routes");
console.log(`${config.site.name} is now listening on http://${IP}:${config.site.port}`);
app.listen(config.site.port);
process.on("SIGINT", function exit() {
process.exit();
});