forked from ranshaw/node-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (28 loc) · 900 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
31
32
33
const Koa = require('koa');
const router = require('koa-router')();
const app = new Koa();
const routerRegister = require('./router/index');
const bodyParser = require('koa-bodyparser');
const cors = require('koa-cors');
const koaJson = require('koa-json');
const serve = require('koa-static');
const logger = require('koa-logger');
const compress = require('koa-compress');
const path = require('path');
const refreshData = require('./refreshData');
const { config } = require('./config');
const port = process.env.PORT || config.port;
app.use(async (ctx, next) => {
console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
await next();
});
app.use(cors());
app.use(koaJson());
app.use(bodyParser());
app.use(compress());
app.use(logger());
routerRegister.register(app);
/*初始化数据*/
refreshData();
app.listen(port);
console.log(`Server started at port ${port}...`);