2021-08-27 03:39:47 +00:00
|
|
|
// @preval
|
|
|
|
/**
|
|
|
|
* Build config: configuration set at build time.
|
2022-11-16 13:32:32 +00:00
|
|
|
* @module soapbox/build-config
|
2021-08-27 03:39:47 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-16 19:32:17 +00:00
|
|
|
const trim = require('lodash/trim');
|
|
|
|
const trimEnd = require('lodash/trimEnd');
|
2021-09-02 21:52:53 +00:00
|
|
|
|
|
|
|
const {
|
2021-09-05 21:42:48 +00:00
|
|
|
NODE_ENV,
|
2021-09-02 21:52:53 +00:00
|
|
|
BACKEND_URL,
|
2021-09-05 18:21:39 +00:00
|
|
|
FE_SUBDIRECTORY,
|
2021-09-03 19:42:31 +00:00
|
|
|
FE_BUILD_DIR,
|
2022-03-21 18:09:01 +00:00
|
|
|
FE_INSTANCE_SOURCE_DIR,
|
2021-09-08 20:45:44 +00:00
|
|
|
SENTRY_DSN,
|
2021-09-02 21:52:53 +00:00
|
|
|
} = process.env;
|
2021-08-27 03:39:47 +00:00
|
|
|
|
|
|
|
const sanitizeURL = url => {
|
|
|
|
try {
|
2021-09-08 16:31:26 +00:00
|
|
|
return trimEnd(new URL(url).toString(), '/');
|
2021-08-27 03:39:47 +00:00
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-03 19:42:31 +00:00
|
|
|
const sanitizeBasename = path => {
|
|
|
|
return `/${trim(path, '/')}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const sanitizePath = path => {
|
|
|
|
return trim(path, '/');
|
2021-09-02 21:52:53 +00:00
|
|
|
};
|
|
|
|
|
2021-08-27 03:39:47 +00: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 21:42:48 +00:00
|
|
|
NODE_ENV: NODE_ENV || 'development',
|
2021-08-27 03:39:47 +00:00
|
|
|
BACKEND_URL: sanitizeURL(BACKEND_URL),
|
2021-09-05 18:21:39 +00:00
|
|
|
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
|
2021-09-03 19:42:31 +00:00
|
|
|
FE_BUILD_DIR: sanitizePath(FE_BUILD_DIR) || 'static',
|
2022-03-21 18:09:01 +00:00
|
|
|
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
|
2021-09-08 20:45:44 +00:00
|
|
|
SENTRY_DSN,
|
2021-08-27 03:39:47 +00:00
|
|
|
});
|