bigbuffet-rw/app/soapbox/build-config.js

47 lines
1 KiB
JavaScript
Raw Normal View History

// @preval
/**
* Build config: configuration set at build time.
2022-11-16 05:32:32 -08:00
* @module soapbox/build-config
*/
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,
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;
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 14:52:53 -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',
BACKEND_URL: sanitizeURL(BACKEND_URL),
2021-09-05 11:21:39 -07:00
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
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,
});