1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/lib/options.js

67 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
2016-12-04 14:09:37 +01:00
2016-12-02 16:34:05 +01:00
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 || process.env.DATABASE_HOST
? defaultDatabaseUrl()
2019-05-22 08:56:30 +02:00
: undefined,
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,
2016-12-02 16:34:05 +01:00
publicFolder,
2016-12-04 14:09:37 +01:00
enableRequestLogger: isDev(),
secret: 'UNLEASH-SECRET',
sessionAge: THIRTY_DAYS,
2019-01-24 11:26:07 +01:00
adminAuthentication: 'unsecure',
2019-03-12 10:46:08 +01:00
ui: {},
importFile: undefined,
dropBeforeImport: false,
getLogger: defaultLogProvider,
};
function defaultDatabaseUrl() {
const dbUsername = process.env.DATABASE_USERNAME || 'unleash_user';
const dbPassword = process.env.DATABASE_PASSWORD || 'passord';
const dbHost = process.env.DATABASE_HOST || 'localhost';
const dbPort = process.env.DATABASE_PORT || 5432;
const dbName = process.env.DATABASE_NAME || 'unleash';
const sslSupport = process.env.DATABASE_SSL || 'true';
return `postgres://${dbUsername}:${dbPassword}@${dbHost}:${dbPort}/${dbName}?ssl=${sslSupport}`;
}
module.exports = {
2017-06-28 10:17:14 +02:00
createOptions: opts => {
2016-12-27 21:03:50 +01:00
const options = Object.assign({}, DEFAULT_OPTIONS, opts);
2016-12-01 00:42:14 +01:00
// If we are running in development we should assume local db
2016-12-04 14:09:37 +01:00
if (isDev() && !options.databaseUrl) {
options.databaseUrl = defaultDatabaseUrl();
2016-12-01 00:42:14 +01:00
}
2016-12-03 13:45:22 +01:00
if (!options.databaseUrl) {
2017-06-28 10:17:14 +02:00
throw new Error(
'You must either pass databaseUrl option or set environemnt variable DATABASE_URL || (DATABASE_HOST, DATABASE_PORT, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME)'
2017-06-28 10:17:14 +02:00
);
}
2019-03-12 10:46:08 +01:00
options.listen = options.pipe
? { path: options.pipe }
: { port: options.port, host: options.host };
validateLogProvider(options.getLogger);
return options;
2016-12-04 14:09:37 +01:00
},
};