-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (46 loc) · 1.38 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
47
48
49
50
51
52
53
54
55
56
57
"use strict"
let express = require('express');
let app = express();
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let configDB = require('./server/config/database');
let multer = require('multer');
let morgan = require('morgan');
let path = require("path");
let favicon = require('serve-favicon');
let port = process.env.PORT || 3000;
let urlDB = process.env.MONGO_URL || configDB.url;
let api = require('./server/routes/api');
let cors = require('cors');
let options = {
server: {
socketOptions: {
keepAlive: 300000,
connectTimeoutMS: 30000
}
},
replset: {
socketOptions: {
keepAlive: 300000,
connectTimeoutMS : 30000
}
}
};
mongoose.connect(urlDB, options, (err, res) => {
mongoose.Promise = global.Promise;
if(err) throw err;
console.info('MongoDB Conectado em %s', urlDB);
});
app.use(cors({ origin: true, credentials: true }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use('/uploads', express.static('server/uploads'));
app.use('/', express.static('dist'));
app.use('/api', api);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.use(favicon(path.join(__dirname, 'server', 'images', 'favicon.ico')));
app.listen(port);
console.log('Magic happens on port: ' + port);