soapbox/app/soapbox/build-config.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

// @preval
/**
* Build config: configuration set at build time.
2022-11-16 13:32:32 +00:00
* @module soapbox/build-config
*/
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,
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;
const sanitizeURL = url => {
try {
return trimEnd(new URL(url).toString(), '/');
} catch {
return '';
}
};
const sanitizeBasename = path => {
return `/${trim(path, '/')}`;
};
const sanitizePath = path => {
return trim(path, '/');
2021-09-02 21:52:53 +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',
BACKEND_URL: sanitizeURL(BACKEND_URL),
2021-09-05 18:21:39 +00:00
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
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,
});