-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (61 loc) · 1.91 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path');
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const logger = require('morgan');
const multer = require('multer');
const helmet = require('helmet');
const OpenApiValidator = require('express-openapi-validator');
const globalErrorHandler = require('./controllers/errorController');
const usersRouter = require('./routes/usersRouter');
const authRouter = require('./routes/authRouter');
const impulseRouter = require('./routes/impulseRouter');
const uploadHelpers = require('./utils/uploadHelpers');
const oapi = require('./utils/openAPI');
const multerMemoryStorage = multer.memoryStorage();
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
// app.use(express.json());
// app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text());
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(oapi);
app.use(
helmet.contentSecurityPolicy({
directives: {
'default-src': [
"'self'",
'bootleg-spatial-recall.fra1.digitaloceanspaces.com',
'bootlegspatialrecall.net',
],
permittedPolicies: 'all',
},
}),
);
app.use(
OpenApiValidator.middleware({
fileUploader: {
storage: multerMemoryStorage,
fileFilter: uploadHelpers.fileFilter,
},
apiSpec: path.join(__dirname, 'public/openapi.json'),
validateResponses: false,
validateRequests: true,
ignorePaths: /.*\/openapi*\/$/,
}),
);
app.use(function (req, res, next) {
res.title = 'Bootleg Spatial Recall';
next();
});
app.use('/auth', authRouter);
app.use('/users', usersRouter);
app.use('/impulses', impulseRouter);
app.use(globalErrorHandler);
module.exports = app;