Factor out API URL to env

This commit is contained in:
2024-11-04 16:13:58 +01:00
parent 5256083f1d
commit 8346e8cd3a
3 changed files with 7 additions and 2 deletions

3
frontend/src/env.ts Normal file
View File

@@ -0,0 +1,3 @@
const API_URL = import.meta.env.API_URL;
export { API_URL };

View File

@@ -1,15 +1,16 @@
--- ---
import Layout from "../layouts/Layout.astro"; import Layout from "../layouts/Layout.astro";
import type { APIResponse, Player, Note } from "../types"; import type { APIResponse, Player, Note } from "../types";
import { API_URL } from "../env";
const res = await fetch("https://stinky-backend.site.quack-lab.dev/player"); const res = await fetch(`${API_URL}/player`);
const data: APIResponse<Player[]> = await res.json(); const data: APIResponse<Player[]> = await res.json();
const request = { success: true, message: "" }; const request = { success: true, message: "" };
if (Astro.request.method === "POST") { if (Astro.request.method === "POST") {
try { try {
const body = await Astro.request.text(); const body = await Astro.request.text();
const res = await fetch("https://stinky-backend.site.quack-lab.dev/note/new", { const res = await fetch(`${API_URL}/note/new`, {
method: "POST", method: "POST",
body, body,
}); });

View File

@@ -1,6 +1,7 @@
--- ---
const { name } = Astro.params; const { name } = Astro.params;
import Layout from '../../layouts/Layout.astro'; import Layout from '../../layouts/Layout.astro';
import { API_URL } from "../../env";
--- ---
<Layout title={name || "Player"}> <Layout title={name || "Player"}>