2016-11-30 23:41:57 +01:00
|
|
|
'use strict';
|
2016-12-04 14:09:37 +01:00
|
|
|
|
2016-12-02 16:34:05 +01:00
|
|
|
const { publicFolder } = require('unleash-frontend');
|
2019-04-30 21:14:23 +02:00
|
|
|
const { defaultLogProvider, validateLogProvider } = require('./logger');
|
2016-11-30 23:41:57 +01:00
|
|
|
|
2016-12-03 14:09:09 +01:00
|
|
|
const isDev = () => process.env.NODE_ENV === 'development';
|
2017-11-16 15:41:33 +01:00
|
|
|
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
|
2016-12-03 14:09:09 +01:00
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
const DEFAULT_OPTIONS = {
|
2016-12-03 13:45:22 +01:00
|
|
|
databaseUrl: process.env.DATABASE_URL,
|
2019-02-01 15:53:03 +01:00
|
|
|
databaseSchema: 'public',
|
2016-11-30 23:41:57 +01:00
|
|
|
port: process.env.HTTP_PORT || process.env.PORT || 4242,
|
2018-05-06 13:01:28 +02:00
|
|
|
host: process.env.HTTP_HOST,
|
2019-04-26 08:45:45 +02:00
|
|
|
pipe: undefined,
|
2016-11-30 23:41:57 +01:00
|
|
|
baseUriPath: process.env.BASE_URI_PATH || '',
|
|
|
|
serverMetrics: true,
|
2017-09-07 21:42:21 +02:00
|
|
|
enableLegacyRoutes: true,
|
2018-12-19 13:17:44 +01:00
|
|
|
extendedPermissions: false,
|
2016-12-02 16:34:05 +01:00
|
|
|
publicFolder,
|
2016-12-04 14:09:37 +01:00
|
|
|
enableRequestLogger: isDev(),
|
2017-11-16 15:41:33 +01:00
|
|
|
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: {},
|
2019-03-13 19:10:13 +01:00
|
|
|
importFile: undefined,
|
|
|
|
dropBeforeImport: false,
|
2019-04-30 21:14:23 +02:00
|
|
|
getLogger: defaultLogProvider,
|
2016-11-30 23:41:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2017-06-28 10:17:14 +02:00
|
|
|
options.databaseUrl =
|
|
|
|
'postgres://unleash_user:passord@localhost:5432/unleash';
|
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'
|
|
|
|
);
|
2016-11-30 23:41:57 +01:00
|
|
|
}
|
2019-03-12 10:46:08 +01:00
|
|
|
|
2019-04-26 08:45:45 +02:00
|
|
|
options.listen = options.pipe
|
|
|
|
? { path: options.pipe }
|
|
|
|
: { port: options.port, host: options.host };
|
|
|
|
|
2019-04-30 21:14:23 +02:00
|
|
|
validateLogProvider(options.getLogger);
|
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
return options;
|
2016-12-04 14:09:37 +01:00
|
|
|
},
|
|
|
|
};
|