-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (55 loc) · 1.5 KB
/
app.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
/*
* @Author: lzr [email protected]
* @Date: 2022-08-28 15:35:19
* @LastEditors: lzr [email protected]
* @LastEditTime: 2022-11-20 15:02:23
* @FilePath: /react-admin-backend/app.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
require('dotenv').config();
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
const uri = "mongodb://localhost:27017/react_admin";
mongoose.connect(uri, {
useNewUrlParser: true,
useCreateIndex: true
});
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
})
const routerList = [{
url: '/api/login',
router: require('./routes/login')
},
// {
// url: '/api/*',
// router: require('./utils/authorization').verifyToken
// },
{
url: '/api/users',
router: require('./routes/users')
},
{
url: '/api/userInfo',
router: require('./routes/userInfo')
},
{
url: '/api/pages',
router: require('./routes/page')
}
]
console.log('---------router list----------')
for (let item of routerList) {
app.use(item.url, item.router)
console.log(item.url)
}
console.log('---------------------------------')
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});