1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/options.js
ivaosthu 9fdb948c69 Implement cookie-session support.
Sessions will be required to solve admin-auth.

I also refactored a few middlewares into seperate
files to make the code easier to read.

closes #262
2017-11-16 15:41:33 +01:00

38 lines
1.1 KiB
JavaScript

'use strict';
const { publicFolder } = require('unleash-frontend');
const isDev = () => process.env.NODE_ENV === 'development';
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
const DEFAULT_OPTIONS = {
databaseUrl: process.env.DATABASE_URL,
port: process.env.HTTP_PORT || process.env.PORT || 4242,
baseUriPath: process.env.BASE_URI_PATH || '',
serverMetrics: true,
enableLegacyRoutes: true,
publicFolder,
enableRequestLogger: isDev(),
secret: 'UNLEASH-SECRET',
sessionAge: THIRTY_DAYS,
};
module.exports = {
createOptions: opts => {
const options = Object.assign({}, DEFAULT_OPTIONS, opts);
// If we are running in development we should assume local db
if (isDev() && !options.databaseUrl) {
options.databaseUrl =
'postgres://unleash_user:passord@localhost:5432/unleash';
}
if (!options.databaseUrl) {
throw new Error(
'You must either pass databaseUrl option or set environemnt variable DATABASE_URL'
);
}
return options;
},
};