This repository was archived by the owner on Jun 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (39 loc) · 1.37 KB
/
app.js
File metadata and controls
53 lines (39 loc) · 1.37 KB
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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
// *************************************
// app
// *************************************
const app = express();
// *************************************
// middlewares
// *************************************
// log requests with response status code
app.use(function(req, res, next) {
res.on('finish', () => console.log('Request: ' + res.statusCode + ' - ' + req.url));
next();
});
// serve some of the files without session lookup
const early_router = express.Router();
app.use(early_router);
// setup request content processing, session handling
app.use(bodyParser.json());
const router = express.Router();
app.use(router);
// *************************************
// routes
// *************************************
// static file routing
const static_files = express.static(path.join(__dirname, 'static/'));
// Api calls must be protected by checking the calling users permissions. Permission handling is omitted here for
// simplicity.
router.use('/api',
require('./app.api')()
);
// At last, serve all static files. This is the right place to check if the user is logged in by the idp, and redirect
// if not.
router.use(
static_files
);
router.get('/', (req, res) => res.redirect('/login.html'));
module.exports = app;