-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (31 loc) · 881 Bytes
/
app.js
File metadata and controls
39 lines (31 loc) · 881 Bytes
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
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import path from 'path';
import config from 'config-lite';
import db from './mongodb/db.js';
import router from './routes/index.js';
import chalk from 'chalk';
const app = express();
// 用于接收post参数
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
// 用于接收cookie
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'), {
maxAge: '30 days'
}));
app.get('/',(req, res, next) => {
res.send('欢迎访问elm-api后台系统,<a href="https://easytuan.gitee.io/node-elm-api/doc" target="_blank">API文档地址</a>');
})
router(app);
app.use((req, res, next) => {
res.send(404);
})
app.listen(config.port, () => {
console.log(
chalk.green(`成功监听端口:${config.port}`)
)
});