pleroma/packages/pl-fe/src/build-config-compiletime.ts

38 lines
807 B
TypeScript
Raw Normal View History

2023-09-13 10:04:17 -07:00
/**
* Build config: configuration set at build time.
* @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 '';
}
};
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),
};
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
});