-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (40 loc) · 1.47 KB
/
index.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
'use strict'
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const cors = require('cors');
const passport = require('passport');
const config = require('./config')
const mongoose = require('mongoose');
const cookieSession = require('cookie-session')
const configDB = require('./db');
const routesConfig = require('./routes');
// const whitelist = ['https://sumarios-poli.netlify.app', 'https://sumarios-elpoli.vercel.app', config.url_front]
// const corsOptions = {
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// callback(null, true)
// } else {
// callback(new Error('Not allowed by CORS'))
// }
// },
// methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
// credentials: true // allow session cookie from browser to pass through
// }
app.use(cors({
origin: config.url_front, // allow to server to accept request from different origin
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true // allow session cookie from browser to pass through
}));
app.use(bodyParser.urlencoded({ extended: false, limit: '50mb' }));
app.use(bodyParser.json({ limit: '50mb' }));
// For an actual app you should configure this with an experation time, better keys, proxy and secure
app.use(cookieSession({
name: 'sumarios-app',
keys: ['key1', 'key2']
}))
app.use(passport.initialize());
app.use(passport.session());
configDB(mongoose);
routesConfig(app);
module.exports = app