-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (46 loc) · 1.29 KB
/
app.js
File metadata and controls
53 lines (46 loc) · 1.29 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
44
45
46
47
48
49
50
51
52
53
const createError = require('http-errors');
const express = require('express');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const helmet = require('helmet');
const passport = require('passport');
const app = express();
require('dotenv').config();
const routes = require('./src/routes');
require('./src/services/passport.service');
app.use(
helmet({
// TODO:
// fix problem with default helmet CSP and browser-sync script
// https://github.com/helmetjs/helmet#reference
// https://github.com/helmetjs/helmet/wiki/Helmet-4-upgrade-guide
// https://github.com/BrowserSync/browser-sync/issues/1395
contentSecurityPolicy: false,
})
);
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(passport.initialize());
app.use(routes);
// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});
// error handler
app.use((err, req, res, next) => {
const status = err.status || 500;
res.status(status).json({
errors: [
{
title: err.message,
detail:
process.env.NODE_ENV === 'development'
? err.stack.split('\n')
: undefined,
},
],
});
});
module.exports = app;