-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (31 loc) · 1.09 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
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const router = require('./router');
const mongoose = require('mongoose');
const logger = require('winston-color');
// DB Setup
mongoose.connect('mongodb://localhost:auth/auth');
const app = express();
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*'); // replace '*' with the domain you're allowing cors
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
next();
};
// App Setup
app.use(morgan('combined'));
app.use(bodyParser.json({ type: '*/*' }));
// Allow CORS
app.use(allowCrossDomain);
// Router Setup
router(app);
// Server Setup
const port = process.env.PORT || 1377;
const server = http.createServer(app);
server.listen(port);
console.log(' ');
logger.info('Server listening on: ', port);
logger.info('---------------------------');