-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 887 Bytes
/
index.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
const unleash = require('unleash-server');
const auth = require('./auth-hooks');
const clientAuth = require('./client-hooks');
const DATABASE_URL = process.env.DATABASE_URL || "postgres://postgres:@defaultdb:5432/unleash";
const SESSION_SECRET = process.env.SESSION_SECRET || "";
const PORT = process.env.PORT || "80";
let hook = null;
switch (process.env.AUTH_TYPE) {
case 'google':
hook = auth.Google;
break;
case 'basic':
hook = auth.Basic;
break;
default:
}
let options = {
databaseUrl: DATABASE_URL,
secret: SESSION_SECRET,
adminAuthentication: 'custom',
enableLegacyRoutes: false,
preRouterHook: app => {
hook(clientAuth.sharedSecret(app)); // add client checks first then admin checks
},
port: PORT,
};
unleash.start(options).then(unleash => {
console.log(
`Unleash started on http://localhost:${unleash.app.get('port')}`,
);
});