2021-08-26 20:39:47 -07:00
|
|
|
// @preval
|
|
|
|
/**
|
|
|
|
* Build config: configuration set at build time.
|
|
|
|
* @module soapbox/build_config
|
|
|
|
*/
|
|
|
|
|
2021-09-02 14:52:53 -07:00
|
|
|
const { trimEnd } = require('lodash');
|
|
|
|
|
|
|
|
const {
|
|
|
|
BACKEND_URL,
|
|
|
|
FE_BASE_PATH,
|
|
|
|
} = process.env;
|
2021-08-26 20:39:47 -07:00
|
|
|
|
|
|
|
const sanitizeURL = url => {
|
|
|
|
try {
|
|
|
|
return new URL(url).toString();
|
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-02 14:52:53 -07:00
|
|
|
// Run Soapbox FE from a subdirectory.
|
|
|
|
const getFeBasePath = () => {
|
2021-09-02 15:09:42 -07:00
|
|
|
return trimEnd(FE_BASE_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({
|
|
|
|
BACKEND_URL: sanitizeURL(BACKEND_URL),
|
2021-09-02 14:52:53 -07:00
|
|
|
FE_BASE_PATH: getFeBasePath(),
|
2021-08-26 20:39:47 -07:00
|
|
|
});
|