-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (38 loc) · 1.25 KB
/
app.js
File metadata and controls
43 lines (38 loc) · 1.25 KB
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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const config = require('./config');
const csrf = require('csurf');
const cookieParser = require('cookie-parser');
app.use(require('helmet')());
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,Authorization');
next();
});
app.use(express.json());
app.set('json spaces', 4);
// -- CSRF --
app.use(cookieParser());
/*app.use(csrf({cookie: true}));
app.get('/', function (req, res) {
res.cookie('XSRF-TOKEN', req.csrfToken(), {sameSite: 'lax'});
res.status(200).json({
message: `Version disponible : v1`
});
});*/
// --
app.use('/v1', require('./api/v1/routes'));
mongoose.connect(`mongodb://${config.db_host}/${config.database}`,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
},
function (error) {
if (error) throw error;
console.log(`Mongoose has been successfully started. (DB=${config.database})`);
});
module.exports = app;