-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1.31 KB
/
server.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
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const db = require('./config/mongokey').mongoUrl
const users = require('./routers/users')
const profiles = require('./routers/profile')
// const history = require('connect-history-api-fallback');
const cors = require('cors')
// 验证token插件
const passport = require('passport')
mongoose.set('useFindAndModify', false)
const app = express()
app.use(cors({credentials: true, origin: 'http://localhost:8080'}))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
// app.use(history())
// 初始化
app.use(passport.initialize());
mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
.then( () => {
console.log('Mongoose 连接成功');
}).catch(err => {
console.log(err);
})
require('./config/passports')(passport)
// app.all("*", function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-control-Allow-Headers", "Authorization");
// res.header("Access-Control-Allow-Methods", "GET,POST,DELETE,PUT,OPTIONS,HEAD,FETCH");
// next();
// })
app.use('/api/user', users)
app.use('/api/profile', profiles)
const port = 3000
app.listen(port, () => {
console.log('Server running...');
})