summaryrefslogtreecommitdiff
path: root/makima/frontend/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'makima/frontend/src/lib')
-rw-r--r--makima/frontend/src/lib/api.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts
new file mode 100644
index 0000000..a6f6c3e
--- /dev/null
+++ b/makima/frontend/src/lib/api.ts
@@ -0,0 +1,40 @@
+const API_CONFIG = {
+ local: {
+ http: "http://localhost:8080",
+ ws: "ws://localhost:8080",
+ },
+ production: {
+ http: "https://api.makima.jp",
+ ws: "wss://api.makima.jp",
+ },
+} as const;
+
+type Environment = "local" | "production";
+
+function detectEnvironment(): Environment {
+ // Check if explicitly set via env var
+ const envOverride = import.meta.env.VITE_API_ENV as Environment | undefined;
+ if (envOverride && (envOverride === "local" || envOverride === "production")) {
+ return envOverride;
+ }
+
+ // Auto-detect based on hostname
+ if (typeof window !== "undefined") {
+ const hostname = window.location.hostname;
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
+ return "local";
+ }
+ }
+
+ return "production";
+}
+
+const env = detectEnvironment();
+
+export const API_BASE = API_CONFIG[env].http;
+export const WS_BASE = API_CONFIG[env].ws;
+export const LISTEN_ENDPOINT = `${WS_BASE}/api/v1/listen`;
+
+export function getEnvironment(): Environment {
+ return env;
+}