diff --git a/bunfig.toml b/bunfig.toml index 9819bf6..a304fa6 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,2 +1,2 @@ [serve.static] -env = "BUN_PUBLIC_*" \ No newline at end of file +env = "PUBLIC_*" \ No newline at end of file diff --git a/package.json b/package.json index ac54376..7d22d1a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "bun --hot src/index.ts", - "build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='BUN_PUBLIC_*'", + "build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='PUBLIC_*'", "start": "NODE_ENV=production bun src/index.ts" }, "dependencies": { @@ -23,4 +23,4 @@ "@types/react-datepicker": "^7.0.0", "@types/react-dom": "^19" } -} +} \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 4659ff1..57902a4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,7 +23,7 @@ export function App() { player_name: playerName !== "all" ? playerName : undefined, limit, }; - const result = await fetchPlexts(params); + const result = await fetchPlexts(process.env.PUBLIC_API_BASE_URL || "", process.env.PUBLIC_API_ENDPOINT || "", process.env.PUBLIC_API_AUTH_CREDENTIALS || "", params); setData(result); } catch (error) { console.error("Error loading data:", error); @@ -62,6 +62,7 @@ export function App() {
+ {process.env.PUBLIC_API_BASE_URL} {loading ? (
diff --git a/src/api.ts b/src/api.ts index b47d844..29c7cfe 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,17 +1,13 @@ import type { ApiResponse } from "./types"; -const API_BASE_URL = "http://localhost:7001"; -const API_ENDPOINT = "/plexts/from-db"; -const AUTH_CREDENTIALS = "root:root"; - -export async function fetchPlexts(params?: { +export async function fetchPlexts(base_url: string, endpoint: string, creds: string, params?: { timestamp_from?: number; timestamp_to?: number; player_name?: string; limit?: number; }): Promise { const headers = new Headers(); - headers.set("Authorization", `Basic ${btoa(AUTH_CREDENTIALS)}`); + headers.set("Authorization", `Basic ${btoa(creds)}`); // Build query string const searchParams = new URLSearchParams(); @@ -29,7 +25,7 @@ export async function fetchPlexts(params?: { } const queryString = searchParams.toString(); - const url = queryString ? `${API_BASE_URL}${API_ENDPOINT}?${queryString}` : `${API_BASE_URL}${API_ENDPOINT}`; + const url = queryString ? `${base_url}${endpoint}?${queryString}` : `${base_url}${endpoint}`; try { const response = await fetch(url, { diff --git a/src/index.ts b/src/index.ts index 863f069..1064998 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,28 +5,6 @@ const server = serve({ routes: { // Serve index.html for all unmatched routes. "/*": index, - - "/api/hello": { - async GET(req) { - return Response.json({ - message: "Hello, world!", - method: "GET", - }); - }, - async PUT(req) { - return Response.json({ - message: "Hello, world!", - method: "PUT", - }); - }, - }, - - "/api/hello/:name": async req => { - const name = req.params.name; - return Response.json({ - message: `Hello, ${name}!`, - }); - }, }, development: process.env.NODE_ENV !== "production" && {