diff --git a/libs/shared/src/config/contextPath.ts b/libs/shared/src/config/contextPath.ts index e90baea01b3..4940b77c18f 100644 --- a/libs/shared/src/config/contextPath.ts +++ b/libs/shared/src/config/contextPath.ts @@ -8,29 +8,43 @@ export enum NovuComponentEnum { export function getContextPath(component: NovuComponentEnum) { let contextPath = ''; - if (process.env.GLOBAL_CONTEXT_PATH) { - contextPath += process.env.GLOBAL_CONTEXT_PATH + '/'; + /** + * Determine if we are running in the browser or in node.js. If we are + * running in node.js, we will have access to the process.env object, + * otherwise we will have access to the window._env_ object to get the + * environment variables. + */ + + // eslint-disable-next-line no-undef + const env = typeof process !== 'undefined' && process?.env ? process?.env : (window as any)._env_; + + if (!env) { + return contextPath; + } + + if (env.GLOBAL_CONTEXT_PATH) { + contextPath += env.GLOBAL_CONTEXT_PATH + '/'; } switch (component) { case NovuComponentEnum.API: - if (process.env.API_CONTEXT_PATH) { - contextPath += process.env.API_CONTEXT_PATH + '/'; + if (env.API_CONTEXT_PATH) { + contextPath += env.API_CONTEXT_PATH + '/'; } break; case NovuComponentEnum.WEB: - if (process.env.FRONT_BASE_CONTEXT_PATH) { - contextPath += process.env.FRONT_BASE_CONTEXT_PATH + '/'; + if (env.FRONT_BASE_CONTEXT_PATH) { + contextPath += env.FRONT_BASE_CONTEXT_PATH + '/'; } break; case NovuComponentEnum.WIDGET: - if (process.env.WIDGET_CONTEXT_PATH) { - contextPath += process.env.WIDGET_CONTEXT_PATH + '/'; + if (env.WIDGET_CONTEXT_PATH) { + contextPath += env.WIDGET_CONTEXT_PATH + '/'; } break; case NovuComponentEnum.WS: - if (process.env.WS_CONTEXT_PATH) { - contextPath += process.env.WS_CONTEXT_PATH + '/'; + if (env.WS_CONTEXT_PATH) { + contextPath += env.WS_CONTEXT_PATH + '/'; } break; }