-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 938 Bytes
/
index.js
File metadata and controls
38 lines (32 loc) · 938 Bytes
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
// Libraries
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const bluebird = require('bluebird');
const morgan = require('morgan');
const config = require('./config/config.js');
const corsOptions = {
origin: '*',
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
};
// Express setup
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors(corsOptions));
// Environment specific setup
if (config.env === 'Development') {
app.use(morgan('dev'));
app.use('/swagger', express.static('swagger'));
} else if (config.env === 'Production') {
app.use(morgan('combined'));
}
// DB
mongoose.Promise = bluebird;
mongoose.connect(config.db);
// Routes
require('./router.js')(app);
// Main
app.listen(config.port);
module.exports = app;