fix env vars

This commit is contained in:
Matteo Rosati
2026-01-16 11:56:21 +01:00
parent e2f7be2813
commit b737c40be6
5 changed files with 8 additions and 33 deletions

View File

@@ -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() {
</header>
<main className="app-main">
{process.env.PUBLIC_API_BASE_URL}
{loading ? (
<div className="loading-container">
<div className="loading-spinner"></div>

View File

@@ -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<ApiResponse> {
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, {

View File

@@ -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" && {