-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (46 loc) · 1.5 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
#!/usr/bin/env node
'use strict';
const _ = require('lodash');
const http = require('http');
const https = require('https');
const path = require('path');
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const packageJson = require('./package.json');
const app = express();
const utils = require('./utils');
const { authorize, token, jwks, login, logout } = require('./api/oauth');
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
utils.populateOptions().then(() => {
const options = utils.getOptions();
const sslOptions = options.ssl
? {
key: options.sslKey,
cert: options.sslCert
}
: {};
const createServer = options.ssl
? _.curry(https.createServer)(sslOptions)
: http.createServer;
const server = createServer(app);
app.route('/version').get((req, res) => {
res.send(packageJson.version);
});
app.route('/authorize').get(authorize);
app.route('/oauth/token').post(token);
app.route('/.well-known/jwks.json').get(jwks)
app.route('/login')
.get((req, res) => {
res.sendFile(path.join(__dirname, 'html/Login.html'));
}).post(login);
app.route('/oidc/logout').get(logout);
server.listen(options.port, () => {
console.info(
`\n\nServer listen at http://localhost:${options.port
}\nwith Options\n${utils.getPrintableString(options)}`
);
});
})