-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (26 loc) · 1.05 KB
/
server.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
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const cors = require('cors');
const Sentry = require("@sentry/node");
const fetch = require("node-fetch");
const indexRouter = require('./routes/index');
const app = express();
Sentry.init({ dsn: "https://[email protected]/5829638" });
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
app.use(logger('dev'));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/', indexRouter(fetch));
// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());
// Optional fallthrough error handler
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + "\n");
});
module.exports = app;