bigbuffet-rw/app/soapbox/build_config.js

42 lines
858 B
JavaScript
Raw Normal View History

// @preval
/**
* Build config: configuration set at build time.
* @module soapbox/build_config
*/
const { trim } = require('lodash');
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,
2021-09-02 14:52:53 -07:00
} = process.env;
const sanitizeURL = url => {
try {
return 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',
});