-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (27 loc) · 810 Bytes
/
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
import mongoose from 'mongoose';
import express from 'express';
import parser from 'body-parser';
import morgan from 'morgan';
import routes from './src/routes';
const app = express();
app.use(morgan('dev'));
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/test',
{
useMongoClient: true,
},
(err) => {
if (err) { console.log('error', err); } else { console.log('Mongoose connected'); }
});
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use(parser.urlencoded({ extended: true }));
app.use(parser.json());
const router = express.Router();
routes(router);
app.use('/', router);
app.listen(3000);
export default app;