fix env vars
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
[serve.static]
|
[serve.static]
|
||||||
env = "BUN_PUBLIC_*"
|
env = "PUBLIC_*"
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun --hot src/index.ts",
|
"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"
|
"start": "NODE_ENV=production bun src/index.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -23,4 +23,4 @@
|
|||||||
"@types/react-datepicker": "^7.0.0",
|
"@types/react-datepicker": "^7.0.0",
|
||||||
"@types/react-dom": "^19"
|
"@types/react-dom": "^19"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ export function App() {
|
|||||||
player_name: playerName !== "all" ? playerName : undefined,
|
player_name: playerName !== "all" ? playerName : undefined,
|
||||||
limit,
|
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);
|
setData(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading data:", error);
|
console.error("Error loading data:", error);
|
||||||
@@ -62,6 +62,7 @@ export function App() {
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main className="app-main">
|
<main className="app-main">
|
||||||
|
{process.env.PUBLIC_API_BASE_URL}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="loading-container">
|
<div className="loading-container">
|
||||||
<div className="loading-spinner"></div>
|
<div className="loading-spinner"></div>
|
||||||
|
|||||||
10
src/api.ts
10
src/api.ts
@@ -1,17 +1,13 @@
|
|||||||
import type { ApiResponse } from "./types";
|
import type { ApiResponse } from "./types";
|
||||||
|
|
||||||
const API_BASE_URL = "http://localhost:7001";
|
export async function fetchPlexts(base_url: string, endpoint: string, creds: string, params?: {
|
||||||
const API_ENDPOINT = "/plexts/from-db";
|
|
||||||
const AUTH_CREDENTIALS = "root:root";
|
|
||||||
|
|
||||||
export async function fetchPlexts(params?: {
|
|
||||||
timestamp_from?: number;
|
timestamp_from?: number;
|
||||||
timestamp_to?: number;
|
timestamp_to?: number;
|
||||||
player_name?: string;
|
player_name?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}): Promise<ApiResponse> {
|
}): Promise<ApiResponse> {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.set("Authorization", `Basic ${btoa(AUTH_CREDENTIALS)}`);
|
headers.set("Authorization", `Basic ${btoa(creds)}`);
|
||||||
|
|
||||||
// Build query string
|
// Build query string
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
@@ -29,7 +25,7 @@ export async function fetchPlexts(params?: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const queryString = searchParams.toString();
|
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 {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
|||||||
22
src/index.ts
22
src/index.ts
@@ -5,28 +5,6 @@ const server = serve({
|
|||||||
routes: {
|
routes: {
|
||||||
// Serve index.html for all unmatched routes.
|
// Serve index.html for all unmatched routes.
|
||||||
"/*": index,
|
"/*": 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" && {
|
development: process.env.NODE_ENV !== "production" && {
|
||||||
|
|||||||
Reference in New Issue
Block a user