fix env vars
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
[serve.static]
|
||||
env = "BUN_PUBLIC_*"
|
||||
env = "PUBLIC_*"
|
||||
@@ -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,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>
|
||||
|
||||
10
src/api.ts
10
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<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, {
|
||||
|
||||
22
src/index.ts
22
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" && {
|
||||
|
||||
Reference in New Issue
Block a user