-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (23 loc) · 681 Bytes
/
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
const koa = require('koa');
const koaBody = require('koa-body');
const cors = require('koa-cors');
const serve = require('koa-static');
const site = require('./Routes/site');
const gameio = require('./game-server');
const { HOST="0.0.0.0", PORT=8080 } = process.env;
const app = koa();
app.use(serve('frontend/dist', { maxage: 5*1000 }));
app
.use(cors())
.use(koaBody())
.use(site.routes())
.use(site.allowedMethods())
.use(function* (next) {
if ("string" == typeof this.body) {
this.body = { message: this.body };
}
});
gameio.attach(app);
app.listen({ host: HOST, port: PORT }, () => {
console.log(`koa server listen at ${HOST}:${PORT}`);
});