-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (30 loc) · 963 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 963 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
import express from 'express';
import http from 'http';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
import compression from 'compression';
import session from 'express-session';
import router from './router';
const app = express();
// MongoDB
mongoose.connect('mongodb://localhost:27017/mongoApis');
mongoose.set('debug', true);
// Server config
app.set('port', 8001);
app.use(compression());
app.use(cors()); // Para hacer white list
app.use(bodyParser.json({ type: '*/*' }));
// Sessions
app.set('trust proxy', 1) // trust first proxy
app.use(session({
secret: 'SoyUnaClavejijij',
resave: false,
saveUninitialized: true,
cookie: { secure: false, maxAge: 1800000 } // Enable if is https maxAge: 30min
}));
router(app);
const server = http.createServer(app);
server.listen(app.get('port'), () => {
console.log('Server is up and listening at http://localhost:%s', app.get('port'));
});