-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (44 loc) · 1.61 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
47
48
49
50
51
52
53
54
55
56
57
var createError = require('http-errors');
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
var mongoose = require('mongoose');
var cors = require('cors');
var helmet = require('helmet');
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://[email protected]/1392749' });
const { MONGODB_HOST, PORT, HOST, ROUTE } = require('./config');
mongoose.connect(MONGODB_HOST, { useNewUrlParser: true });
mongoose.connection.on('error', console.error.bind(console, 'connection error: '));
mongoose.connection.once('open', () => {
console.log('DB Connected');
var app = express();
app.use(Sentry.Handlers.requestHandler());
app.use(logger('dev'));
app.use(cors());
app.use(helmet());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.use(cookieParser());
app.set('trust proxy', true);
app.set('trust proxy', 'loopback');
var router = require("./routes");
app.use(ROUTE, router);
app.get('/', (req, res) => {
res.status(200).send('Internship Server - WellyCompSci');
});
app.use(Sentry.Handlers.errorHandler());
// catch 404 errors
app.use((req, res, next) => {
next(createError(404, `${req.originalUrl} - 404 not found on ${req.protocol}//${req.get('Host')}`));
});
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send('Something broke!');
res.end(res.sentry + '\n');
})
app.listen(PORT, HOST);
});