-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (49 loc) · 1.44 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
require('dotenv').load();
const express = require('express');
const http = require('http');
const logger = require('morgan');
const path = require('path');
const router = require('./routes/index');
const { auth } = require('express-openid-connect');
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
const config = {
authRequired: false,
auth0Logout: true,
// authorizationParams: {
// organization: "org_N3J7VwhVgEjt6bPN"
// }
};
const port = process.env.PORT || 3000;
if (!config.baseURL && !process.env.BASE_URL && process.env.PORT && process.env.NODE_ENV !== 'production') {
config.baseURL = `http://localhost:${port}`;
}
app.use(auth(config));
// Middleware to make the `user` object available for all views
app.use(function (req, res, next) {
res.locals.user = req.oidc.user;
next();
});
app.use('/', router);
// Catch 404 and forward to error handler
app.use(function (req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// Error handlers
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: process.env.NODE_ENV !== 'production' ? err : {}
});
});
http.createServer(app)
.listen(port, () => {
console.log(`Listening on ${config.baseURL}`);
});