2018-01-04 15:48:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// const unleash = require('unleash-server');
|
|
|
|
const unleash = require('../lib/server-impl.js');
|
|
|
|
|
|
|
|
// You typically will not hard-code this value in your code!
|
|
|
|
const sharedSecret = '12312Random';
|
|
|
|
|
|
|
|
unleash
|
|
|
|
.start({
|
|
|
|
databaseUrl: 'postgres://unleash_user:passord@localhost:5432/unleash',
|
|
|
|
enableLegacyRoutes: false,
|
|
|
|
preRouterHook: app => {
|
|
|
|
app.use('/api/client', (req, res, next) => {
|
2018-07-21 09:52:53 +02:00
|
|
|
if (req.header('authorization') === sharedSecret) {
|
2018-07-12 16:15:02 +02:00
|
|
|
next();
|
2018-07-21 09:52:53 +02:00
|
|
|
} else {
|
|
|
|
res.sendStatus(401);
|
2018-01-04 15:48:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(server => {
|
2020-04-14 22:29:11 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2018-01-04 15:48:48 +01:00
|
|
|
console.log(
|
2020-04-14 22:29:11 +02:00
|
|
|
`Unleash started on http://localhost:${server.app.get('port')}`,
|
2018-01-04 15:48:48 +01:00
|
|
|
);
|
|
|
|
});
|