1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/options.js
ivaosthu ccaab0c47b fix: LogProvider as option injected to unleash.
Instead of instructing users to do static calls
in to Unleash, she should instead be allwed to
specify the log provider as an option to Unleash.

This commit introduces the "getLogger" option,
a function responsible for creating a logger.
2020-02-20 08:34:24 +01:00

55 lines
1.6 KiB
JavaScript

'use strict';
const { publicFolder } = require('unleash-frontend');
const { defaultLogProvider, validateLogProvider } = require('./logger');
const isDev = () => process.env.NODE_ENV === 'development';
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
const DEFAULT_OPTIONS = {
databaseUrl: process.env.DATABASE_URL,
databaseSchema: 'public',
port: process.env.HTTP_PORT || process.env.PORT || 4242,
host: process.env.HTTP_HOST,
pipe: undefined,
baseUriPath: process.env.BASE_URI_PATH || '',
serverMetrics: true,
enableLegacyRoutes: true,
extendedPermissions: false,
publicFolder,
enableRequestLogger: isDev(),
secret: 'UNLEASH-SECRET',
sessionAge: THIRTY_DAYS,
adminAuthentication: 'unsecure',
ui: {},
importFile: undefined,
dropBeforeImport: false,
getLogger: defaultLogProvider,
};
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'
);
}
options.listen = options.pipe
? { path: options.pipe }
: { port: options.port, host: options.host };
validateLogProvider(options.getLogger);
return options;
},
};