2021-08-26 20:39:47 -07:00
|
|
|
// @preval
|
|
|
|
/**
|
|
|
|
* Build config: configuration set at build time.
|
|
|
|
* @module soapbox/build_config
|
|
|
|
*/
|
|
|
|
|
2022-06-16 12:32:17 -07:00
|
|
|
const trim = require('lodash/trim');
|
|
|
|
const trimEnd = require('lodash/trimEnd');
|
2021-09-02 14:52:53 -07:00
|
|
|
|
|
|
|
const {
|
2021-09-05 14:42:48 -07:00
|
|
|
NODE_ENV,
|
2021-09-02 14:52:53 -07:00
|
|
|
BACKEND_URL,
|
2021-09-05 11:21:39 -07:00
|
|
|
FE_SUBDIRECTORY,
|
2021-09-03 12:42:31 -07:00
|
|
|
FE_BUILD_DIR,
|
2022-03-21 11:09:01 -07:00
|
|
|
FE_INSTANCE_SOURCE_DIR,
|
2021-09-08 13:45:44 -07:00
|
|
|
SENTRY_DSN,
|
2021-09-02 14:52:53 -07:00
|
|
|
} = process.env;
|
2021-08-26 20:39:47 -07:00
|
|
|
|
|
|
|
const sanitizeURL = url => {
|
|
|
|
try {
|
2021-09-08 09:31:26 -07:00
|
|
|
return trimEnd(new URL(url).toString(), '/');
|
2021-08-26 20:39:47 -07:00
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-03 12:42:31 -07:00
|
|
|
const sanitizeBasename = path => {
|
|
|
|
return `/${trim(path, '/')}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const sanitizePath = path => {
|
|
|
|
return trim(path, '/');
|
2021-09-02 14:52:53 -07:00
|
|
|
};
|
|
|
|
|
2021-08-26 20:39:47 -07:00
|
|
|
// JSON.parse/stringify is to emulate what @preval is doing and avoid any
|
|
|
|
// inconsistent behavior in dev mode
|
|
|
|
const sanitize = obj => JSON.parse(JSON.stringify(obj));
|
|
|
|
|
|
|
|
module.exports = sanitize({
|
2021-09-05 14:42:48 -07:00
|
|
|
NODE_ENV: NODE_ENV || 'development',
|
2021-08-26 20:39:47 -07:00
|
|
|
BACKEND_URL: sanitizeURL(BACKEND_URL),
|
2021-09-05 11:21:39 -07:00
|
|
|
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
|
2021-09-03 12:42:31 -07:00
|
|
|
FE_BUILD_DIR: sanitizePath(FE_BUILD_DIR) || 'static',
|
2022-03-21 11:09:01 -07:00
|
|
|
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
|
2021-09-08 13:45:44 -07:00
|
|
|
SENTRY_DSN,
|
2021-08-26 20:39:47 -07:00
|
|
|
});
|