forked from AltCamp/altcampv1-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (50 loc) · 1.5 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
const express = require('express');
const Sentry = require('@sentry/node');
const initializeSentry = require('./middleware/sentry');
const cookieParser = require('cookie-parser');
const morgan = require('morgan');
const { Logger } = require('./utils');
const { errorHandler } = require('./utils/errorHandler');
const cors = require('cors');
require('express-async-errors');
const { ALT_CAMP } = require('./constant');
const indexRouter = require('./routes/index');
const {
app: { env },
} = require('./config');
const app = express();
initializeSentry();
require('./src/common/cache');
const appConfig = (app) => {
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
app.use(cors());
if (env === 'test') {
app.use(morgan('dev'));
} else {
global.logger = Logger.createLogger({ label: ALT_CAMP });
app.use(morgan('combined', { stream: logger.stream }));
}
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: false }));
app.use(express.static('public'));
app.use(cookieParser());
app.get('/', (req, res) => {
res.send('Lets make magic! 🚀');
});
app.use('/', indexRouter);
app.use(
Sentry.Handlers.errorHandler({
shouldHandleError(error) {
// Capture all 404 and 500 errors
if (error.statusCode === 404 || error.statusCode === 500) {
return true;
}
return false;
},
})
);
app.use(errorHandler);
};
appConfig(app);
module.exports = app;