1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 08:28:09 +00:00

use import.meta.env.QUOT_API_URL

This commit is contained in:
Nebel 2022-08-29 01:02:47 +09:00
parent cfe0fd3a1b
commit ae22560a87
4 changed files with 29 additions and 9 deletions

5
app/src/env.d.ts vendored Normal file
View file

@ -0,0 +1,5 @@
interface ImportMeta {
env: {
QUOT_API_URL: string;
};
}

View file

@ -4,7 +4,9 @@ import Cards from "../components/cards";
import Card from "../components/card"; import Card from "../components/card";
async function fetchPages(): Promise<Pages.Response> { async function fetchPages(): Promise<Pages.Response> {
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; const data = (await res.json()) as Pages.Response;
return data; return data;
} }

View file

@ -11,21 +11,29 @@ async function updatePage(
id: number, id: number,
content: Pages.RequestContentPage content: Pages.RequestContentPage
): Promise<boolean> { ): Promise<boolean> {
const res = await fetch(`/api/pages?id=eq.${id}`, { const res = await fetch(
`${import.meta.env.QUOT_API_URL}/api/pages?id=eq.${id}`,
{
method: "PUT", method: "PUT",
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
body: JSON.stringify(content), body: JSON.stringify(content),
}); }
);
return res.ok; return res.ok;
} }
async function deletePage(id: number): Promise<boolean> { async function deletePage(id: number): Promise<boolean> {
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; return res.ok;
} }
async function fetchPage(id: number): Promise<Pages.ResponsePage> { async function fetchPage(id: number): Promise<Pages.ResponsePage> {
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; const data = (await res.json()) as Pages.Response;
return data[0]!; return data[0]!;
} }

View file

@ -5,7 +5,7 @@ import esbuild from "esbuild";
async function main() { async function main() {
const port = Number(process.env.PORT ?? "8080"); 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 publicDir = __dirname;
const htmlPath = `${publicDir}/index.html`; const htmlPath = `${publicDir}/index.html`;
const scriptPath = `${publicDir}/index.ts`; const scriptPath = `${publicDir}/index.ts`;
@ -19,6 +19,11 @@ async function main() {
bundle: true, bundle: true,
minify: true, minify: true,
entryPoints: [scriptPath], entryPoints: [scriptPath],
define: {
"import.meta.env.QUOT_API_URL": JSON.stringify(
process.env.QUOT_API_URL ?? ""
),
},
} }
); );