diff --git a/app/src/env.d.ts b/app/src/env.d.ts new file mode 100644 index 0000000..5e56e54 --- /dev/null +++ b/app/src/env.d.ts @@ -0,0 +1,5 @@ +interface ImportMeta { + env: { + QUOT_API_URL: string; + }; +} diff --git a/app/src/pages/index.tsx b/app/src/pages/index.tsx index 354441f..84590f9 100644 --- a/app/src/pages/index.tsx +++ b/app/src/pages/index.tsx @@ -4,7 +4,9 @@ import Cards from "../components/cards"; import Card from "../components/card"; async function fetchPages(): Promise { - const res = await fetch("/api/pages?order=updated.desc"); + const res = await fetch( + `${import.meta.env.QUOT_API_URL}/api/pages?order=updated.desc` + ); const data = (await res.json()) as Pages.Response; return data; } diff --git a/app/src/pages/page.tsx b/app/src/pages/page.tsx index 4fedcd6..ccc1596 100644 --- a/app/src/pages/page.tsx +++ b/app/src/pages/page.tsx @@ -11,21 +11,29 @@ async function updatePage( id: number, content: Pages.RequestContentPage ): Promise { - const res = await fetch(`/api/pages?id=eq.${id}`, { - method: "PUT", - headers: { "content-type": "application/json" }, - body: JSON.stringify(content), - }); + const res = await fetch( + `${import.meta.env.QUOT_API_URL}/api/pages?id=eq.${id}`, + { + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify(content), + } + ); return res.ok; } async function deletePage(id: number): Promise { - const res = await fetch(`/api/pages?id=eq.${id}`, { method: "DELETE" }); + const res = await fetch( + `${import.meta.env.QUOT_API_URL}/api/pages?id=eq.${id}`, + { method: "DELETE" } + ); return res.ok; } async function fetchPage(id: number): Promise { - const res = await fetch(`/api/pages?id=eq.${id}`); + const res = await fetch( + `${import.meta.env.QUOT_API_URL}/api/pages?id=eq.${id}` + ); const data = (await res.json()) as Pages.Response; return data[0]!; } diff --git a/app/src/server.ts b/app/src/server.ts index 0ce8656..19f85c8 100644 --- a/app/src/server.ts +++ b/app/src/server.ts @@ -5,7 +5,7 @@ import esbuild from "esbuild"; async function main() { const port = Number(process.env.PORT ?? "8080"); - const apiUrl = process.env.QUOT_API_URL || "http://127.0.0.1:3000/"; + const apiUrl = process.env.QUOT_API_URL || "http://127.0.0.1:3000"; const publicDir = __dirname; const htmlPath = `${publicDir}/index.html`; const scriptPath = `${publicDir}/index.ts`; @@ -19,6 +19,11 @@ async function main() { bundle: true, minify: true, entryPoints: [scriptPath], + define: { + "import.meta.env.QUOT_API_URL": JSON.stringify( + process.env.QUOT_API_URL ?? "" + ), + }, } );