cv/app/frontend/src/config/environment.ts
2023-06-02 12:35:51 +02:00

43 lines
919 B
TypeScript

interface ConfigFromBackend {
commitTime: string;
contactEmail: string;
contactPhone: string;
position: string;
}
interface MyWindow extends Window {
APP_CONFIG?: ConfigFromBackend;
}
declare const window: MyWindow;
const confString = (input: string | undefined, def: string): string => {
if (
input === undefined ||
(typeof input === "string" && input.trim() === "")
) {
return def;
}
return input;
};
export const BUILD_TIMESTAMP: Date = window.APP_CONFIG?.commitTime
? new Date(window.APP_CONFIG.commitTime)
: new Date();
export const CONTACT_EMAIL = confString(
window.APP_CONFIG?.contactEmail,
import.meta.env.VITE_CONTACT_EMAIL || ""
);
export const CONTACT_PHONE = confString(
window.APP_CONFIG?.contactPhone,
import.meta.env.VITE_CONTACT_PHONE || ""
);
export const POSITION = confString(
window.APP_CONFIG?.position,
import.meta.env.VITE_POSITION || ""
);