65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
export const JR_DATA_SYSTEM_ENVS = {
|
|
production: {
|
|
label: "本番",
|
|
caption: "現在の本番環境",
|
|
baseUrl: "https://jr-shikoku-data-system.pages.dev",
|
|
},
|
|
chatgpt: {
|
|
label: "ChatGPT",
|
|
caption: "experiment-ux-refactoring-co-3crz",
|
|
baseUrl:
|
|
"https://experiment-ux-refactoring-co-3crz.jr-shikoku-data-system.pages.dev",
|
|
},
|
|
claude: {
|
|
label: "Claude",
|
|
caption: "experiment-ux-refactoring-co-6cw7",
|
|
baseUrl:
|
|
"https://experiment-ux-refactoring-co-6cw7.jr-shikoku-data-system.pages.dev",
|
|
},
|
|
} as const;
|
|
|
|
export type JrDataSystemEnvironmentKey = keyof typeof JR_DATA_SYSTEM_ENVS;
|
|
|
|
export const DEFAULT_JR_DATA_SYSTEM_ENV: JrDataSystemEnvironmentKey =
|
|
"production";
|
|
|
|
export const JR_DATA_SYSTEM_ENV_OPTIONS = (
|
|
Object.entries(JR_DATA_SYSTEM_ENVS) as [
|
|
JrDataSystemEnvironmentKey,
|
|
(typeof JR_DATA_SYSTEM_ENVS)[JrDataSystemEnvironmentKey],
|
|
][]
|
|
).map(([key, value]) => ({
|
|
key,
|
|
...value,
|
|
}));
|
|
|
|
export const normalizeJrDataSystemEnvironment = (
|
|
value: unknown,
|
|
): JrDataSystemEnvironmentKey => {
|
|
if (typeof value === "string" && value in JR_DATA_SYSTEM_ENVS) {
|
|
return value as JrDataSystemEnvironmentKey;
|
|
}
|
|
return DEFAULT_JR_DATA_SYSTEM_ENV;
|
|
};
|
|
|
|
export const rewriteJrDataSystemUrl = (
|
|
uri: string,
|
|
environment: unknown,
|
|
): string => {
|
|
if (typeof uri !== "string" || uri.length === 0) {
|
|
return uri;
|
|
}
|
|
|
|
const envKey = normalizeJrDataSystemEnvironment(environment);
|
|
if (envKey === DEFAULT_JR_DATA_SYSTEM_ENV) {
|
|
return uri;
|
|
}
|
|
|
|
const productionBaseUrl = JR_DATA_SYSTEM_ENVS.production.baseUrl;
|
|
const targetBaseUrl = JR_DATA_SYSTEM_ENVS[envKey].baseUrl;
|
|
|
|
return uri.startsWith(productionBaseUrl)
|
|
? uri.replace(productionBaseUrl, targetBaseUrl)
|
|
: uri;
|
|
};
|