This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
84 lines (73 loc) · 2.31 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import express from 'express';
import path from 'path';
import favicon from 'serve-favicon';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import logger from 'morgan';
import JWTAuth from './jwt/jwt';
import article from './router/article';
import aplayer from './router/player';
import project from './router/project';
import cover from './router/cover';
import motto from './router/motto';
import announcement from './router/announcement';
import liveTour from './router/liveTour';
import featuredRecord from './router/featuredRecord';
import yanceyMusic from './router/yanceyMusic';
import workExperience from './router/workExperience';
import programExperience from './router/programExperience';
import about from './router/about';
import user from './router/user';
import bandwagon from './router/bandwagon';
import uploader from './tools/uploader';
import userInfo from './router/userInfo';
import globalStatus from './router/globalStatus';
const app = express();
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/blog',
{useNewUrlParser: true}
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static('dist'));
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', '*');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('Access-Control-Expose-Headers', '*');
if (req.method === 'OPTIONS') {
res.send(200);
}
else {
next();
}
});
app.use(JWTAuth);
app.use((err, req, res, next) => {
if (err.name === 'UnauthorizedError') {
res.status(401).json(err);
}
next();
});
app.use('/api', article);
app.use('/api', aplayer);
app.use('/api', project);
app.use('/api', cover);
app.use('/api', motto);
app.use('/api', announcement);
app.use('/api', liveTour);
app.use('/api', featuredRecord);
app.use('/api', yanceyMusic);
app.use('/api', workExperience);
app.use('/api', programExperience);
app.use('/api', about);
app.use('/api', uploader);
app.use('/api', user);
app.use('/api', bandwagon);
app.use('/api', userInfo);
app.use('/api', globalStatus);
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.listen(3001, () => {
console.log('listening on port 3001')
});
module.exports = app;