-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·40 lines (33 loc) · 1.23 KB
/
cli.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
#!/usr/bin/env node
const path = require('path');
const express = require('express');
const morgan = require('morgan');
const oidcRouter = require('./index');
const oidcApiProxy = require('./oidcApiProxy');
const { backend, oidc } = require('./config');
const app = express();
if (backend.log && backend.log.format) {
app.use(morgan(backend.log.format));
}
// Authentication endpoint
app.use(backend.path, oidcRouter(oidc));
// Api proxy
if (backend.apiProxy && backend.apiProxy.target) {
app.use(backend.apiProxy.path, oidcApiProxy(backend.apiProxy.target, oidc.storeName));
}
// Proxying
if (backend.static) {
console.log(`Serving ${backend.static}...`);
app.use(express.static(backend.static));
} else if (backend.proxy && backend.proxy.target) {
console.log(`Forwarding requests to ${backend.proxy.target}...`);
// eslint-disable-next-line global-require
const proxy = require('http-proxy-middleware'); // optional dep
app.use(proxy(backend.proxy));
} else {
console.log('No backend config set via --backend.static or --backend.proxy.target, serving example...');
app.use(express.static(path.join(__dirname, 'public')));
}
app.listen(backend.port, () => {
console.log(`Listening on http://localhost:${backend.port}`);
});