-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (39 loc) · 1.13 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
const express = require("express");
const app = express();
const mongoose = require('mongoose');
const gift = require('./routes/gift');
const admin = require('./routes/admin');
const cors = require('cors');
//body-parser
var bodyParser = require('body-parser')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
const port = 3000;
app.use(express.json());
// 使用 cors 中间件
app.use(cors());
// 连接MongoDB
mongoose.connect('mongodb://localhost:27017/recruitmentGift', {
useNewUrlParser: true,
useUnifiedTopology: true
}).then((dbo)=>{
// console.log("DB Connected!");
},(err)=>{
console.warn("!!!!!! DB connection is error, please check DB!\n>>>>>> Process will stop!");
process.exit(1);
});
// 路由
app.use("/gift", gift);
app.use("/admin", admin);
// 根路由
app.get("/",(req,res)=>{
// res.send("Hello,World!");
res.send("Welcome to <b>CPU Club</b> !");
} );
app.post("/", (req, res) => {
res.send("Surprise!");
});
//监听3000端口
app.listen(port, () => {
console.log(`>>>>> Services started at http://localhost:${port} !\n>>>>> Please check database status!`)
});