Factor out API URL to env
This commit is contained in:
3
frontend/src/env.ts
Normal file
3
frontend/src/env.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const API_URL = import.meta.env.API_URL;
|
||||||
|
|
||||||
|
export { API_URL };
|
@@ -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,
|
||||||
});
|
});
|
||||||
|
@@ -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"}>
|
||||||
|
Reference in New Issue
Block a user