18 lines
590 B
TypeScript
18 lines
590 B
TypeScript
/// <reference types="node" />
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
function readDevelopmentApiBaseUrl(): string {
|
|
const envFile = readFileSync(resolve(process.cwd(), ".env.development"), "utf8");
|
|
const line = envFile.split("\n").find((entry) => entry.startsWith("VITE_API_BASE_URL="));
|
|
|
|
if (line === undefined) {
|
|
throw new Error("VITE_API_BASE_URL is missing from .env.development");
|
|
}
|
|
|
|
return line.slice("VITE_API_BASE_URL=".length).trim();
|
|
}
|
|
|
|
export const apiBaseUrl = process.env.VITE_API_BASE_URL ?? readDevelopmentApiBaseUrl();
|