-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
76 lines (63 loc) · 2.49 KB
/
app.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
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var session = require('express-session');
var config = require('config');
var app = express();
// View engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.locals.title = 'Pedigree Browser';
// Allow the app to be run behind proxies. The app will detect when it's behind
// a proxy and properly configure https and other settings based on the user's
// connection to the proxy instead of the proxies connection to server.
// https://expressjs.com/en/guide/behind-proxies.html
app.set('trust proxy', true);
// Enable session storage. This defaults to using an in-memory store which is
// only designed for development environments. It will leak memory. Use a
// different storage adapter in production, such as redis.
// https://www.npmjs.com/package/express-session
//
// We use the session to store the FS access token and the current user data.
app.use(session({
secret: 'pedigree browser session secret',
resave: false,
saveUninitialized: false,
cookie: { secure: config.get('session.cookie.secure') }
}));
// Use morgan to log all incoming requests. Defaults to Apache style logs.
app.use(logger('dev'));
// Configure serving of static assets.
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
// Make the session available in templates and default to an empty object. If we
// don't default to an empty object then we would have to check for its
// existence before accessing data in templates.
app.use(function(req, res, next){
res.locals.session = req.session || {};
next();
});
// Attach routes
app.use('/', require('./routes/index'));
app.use('/signin', require('./routes/signin'));
app.use('/signout', require('./routes/signout'));
app.use('/oauth-redirect', require('./routes/oauth-redirect'));
app.use('/pedigree', require('./routes/pedigree'));
// Catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// Error handler
app.use(function(err, req, res, next) {
// Set locals (template variables)
// Only provide the error details in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// Render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;