-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
60 lines (45 loc) · 1.33 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
/**
* Entry point of the service provider(FS) demo app.
*/
const
express = require('express'),
session = require('express-session'),
sessionstore = require('sessionstore'),
bodyParser = require('body-parser');
const {
localLogin,
localLogout
} = require('./controllers/localAuthController');
const {
oidcLoginAuthorize,
oidcLoginCallback,
oidcLogout,
} = require('./controllers/oidcAuthController');
const app = express();
// Note this enable to store user session in memory
// As a consequence, restarting the node process will wipe all sessions data
app.use(session({
store: sessionstore.createSessionStore(),
secret: 'demo secret',
cookie: {},
saveUninitialized: true,
resave: true,
}));
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.set('view engine', 'ejs');
app.get('/', (req, res) => res.render('home', {
user: req.session.user
}));
app.post('/login', localLogin);
app.get('/logout', oidcLogout);
app.get('/logout-callback', localLogout);
app.post('/login-authorize', oidcLoginAuthorize);
app.get('/login-callback', oidcLoginCallback);
// Setting app port
const port = process.env.PORT || '3000';
// Starting server
const server = app.listen(port, () => {
console.log(`\x1b[32mServer listening on http://localhost:${port}\x1b[0m`);
});