generated from labs15-music-meteorologist/frontend
-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
46 lines (35 loc) · 1.23 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
39
40
41
42
43
44
45
46
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');
const morgan = require('morgan');
require('dotenv').config();
const UsersRouter = require('./api/users/user-router.js');
const RecommenderRouter = require('./api/recommendations/recommendation.js');
const server = express();
const Sentry = require('@sentry/node');
Sentry.init({
dsn: 'https://[email protected]/1537793',
});
server.use(Sentry.Handlers.requestHandler());
server.use(express.json());
server.use(helmet());
server.use(morgan('dev'));
server.use(cors());
server.get('/', function rootHandler(req, res) {
res.send(
`Welcome to the ${process.env.DEPLOYMENT} environment API of Music Meteorologist!`,
);
});
server.get('/debug-sentry', function mainHandler(req, res) {
throw new Error('My first Sentry error!');
});
server.use(Sentry.Handlers.errorHandler());
server.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');
});
server.use('/v1/users', UsersRouter);
server.use('/v1/recommender', RecommenderRouter);
module.exports = server;