-
Notifications
You must be signed in to change notification settings - Fork 93
/
index.js
67 lines (62 loc) · 1.53 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
56
57
58
59
60
61
62
63
64
65
66
67
const Koa = require('koa');
const path = require('path');
const session = require('koa-session-minimal');
const MysqlStore = require('koa-mysql-session');
const config = require('./config/default.js');
const staticCache = require('koa-static-cache');
const views = require('koa-views');
const koaBody = require('koa-body');
const compress = require('koa-compress');
const logger = require('koa-logger');
const cors = require('koa-cors');
const router = require('koa-router');
const route = new router();
const app = new Koa();
const sessionMysqlConfig = {
user: config.database.USER,
password: config.database.PASSWORD,
host: config.database.HOST,
database: config.database.DATABASE,
};
app.use(logger());
app.use(cors());
app.use(
session({
key: 'USER_SID',
store: new MysqlStore(sessionMysqlConfig),
}),
);
app.use(
staticCache(
path.join(__dirname, './public'),
{ dynamic: true },
{
maxAge: 365 * 24 * 60 * 60,
},
),
);
app.use(
staticCache(
path.join(__dirname, './public/avator'),
{ dynamic: true },
{
maxAge: 365 * 24 * 60 * 60,
},
),
);
app.use(
views(path.join(__dirname, './views'), {
extension: 'ejs',
}),
);
app.use(compress({ threshold: 2048 }));
app.use(require('./router/admin.js').routes()).use(route.allowedMethods());
app.use(require('./router/mobile.js').routes()).use(route.allowedMethods());
app.use(
koaBody({
multipart: true,
formidable: { uploadDir: path.join(__dirname, './public/images') },
}),
);
app.listen(3000);
console.log('listen in 3000');