-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
83 lines (69 loc) · 2.09 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const path = require('path')
require('dotenv').config({
path: path.resolve(__dirname, '.env'),
})
const express = require('express')
const helmet = require('helmet')
const cors = require('cors')
const app = express()
const Sentry = require('@sentry/node')
const passport = require('passport')
const bodyParser = require('body-parser')
Sentry.init({
dsn: process.env.DSN,
})
app.use(Sentry.Handlers.requestHandler())
app.use(bodyParser.json())
app.use(passport.initialize())
app.use(Sentry.Handlers.errorHandler())
app.use(helmet())
const allowedOrigins = ['http://localhost:8100', 'https://demo.ooly.fr', 'https://jury.ooly.fr']
app.use(
cors({
origin: function (origin, callback) {
// allow requests with no origin
// (like mobile apps or curl requests)
if (!origin) return callback(null, true)
if (allowedOrigins.indexOf(origin) === -1) {
const msg = 'The CORS policy for this site does not ' + 'allow access from the specified Origin.'
return callback(new Error(msg), false)
}
return callback(null, true)
},
}),
)
// Optional fallthrough error handler
/* istanbul ignore next */
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.
/* istanbul ignore next */
res.statusCode = 500
/* istanbul ignore next */
res.end(res.sentry + '\n')
})
// Authentication strategies
require('./strategies/login')
require('./strategies/register')
require('./strategies/jwt')
require('./routes/base')(app)
require('./routes/auth')(app)
require('./routes/user')(app)
require('./routes/oo')(app)
require('./routes/feedback')(app)
require('./routes/scenario')(app)
passport.serializeUser(function (user, done) {
done(null, user)
})
passport.deserializeUser(function (user, done) {
/* istanbul ignore next */
done(null, user)
})
app.use('/docs', express.static('documentation'))
const server = app.listen(process.env.SERVER_PORT, function () {
console.log(`Server is running on port ${process.env.SERVER_PORT}`)
})
module.exports = {
app,
server,
}