2023-09-13 10:04:17 -07:00
|
|
|
/**
|
|
|
|
* Build config: configuration set at build time.
|
2024-08-28 04:41:08 -07:00
|
|
|
* @module pl-fe/build-config
|
2023-09-13 10:04:17 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/extensions
|
|
|
|
import trim from 'lodash/trim.js';
|
|
|
|
// eslint-disable-next-line import/extensions
|
|
|
|
import trimEnd from 'lodash/trimEnd.js';
|
|
|
|
|
|
|
|
const {
|
|
|
|
NODE_ENV,
|
|
|
|
BACKEND_URL,
|
|
|
|
FE_SUBDIRECTORY,
|
|
|
|
} = process.env;
|
|
|
|
|
|
|
|
const sanitizeURL = (url: string | undefined = ''): string => {
|
|
|
|
try {
|
|
|
|
return trimEnd(new URL(url).toString(), '/');
|
|
|
|
} catch {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-12 16:18:04 -07:00
|
|
|
const sanitizeBasename = (path: string | undefined = ''): string => `/${trim(path, '/')}`;
|
2023-09-13 10:04:17 -07:00
|
|
|
|
2023-09-20 14:02:36 -07:00
|
|
|
const env = {
|
|
|
|
NODE_ENV: NODE_ENV || 'development',
|
|
|
|
BACKEND_URL: sanitizeURL(BACKEND_URL),
|
|
|
|
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
|
|
|
|
};
|
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
export type PlFeEnv = typeof env;
|
2023-09-20 14:02:36 -07:00
|
|
|
|
2023-09-13 10:04:17 -07:00
|
|
|
export default () => ({
|
2023-09-20 14:02:36 -07:00
|
|
|
data: env,
|
2023-09-13 10:04:17 -07:00
|
|
|
});
|