This commit is contained in:
waltem01 2023-11-30 09:19:07 +01:00
parent f2f702099f
commit 3a105c79dd

View File

@ -2,11 +2,9 @@ import type { APIResponse } from "$lib/interfaces";
import { json, type RequestHandler } from "@sveltejs/kit";
export const GET: RequestHandler = async ({ url }) => {
const response = { success: false } as APIResponse;
const params = url.searchParams;
const endpoint = params.get('endpoint');
if (endpoint === null) return json(response);
if (endpoint === null) return json({ success: false } as APIResponse);
const api_call = await fetch(`http://localhost:8080/${endpoint}`);
const data = await api_call.json() as APIResponse;
@ -14,11 +12,9 @@ export const GET: RequestHandler = async ({ url }) => {
};
export const POST: RequestHandler = async ({ request }) => {
const response = { success: false } as APIResponse;
const formData = await request.formData();
const endpoint = formData.get('endpoint');
if (endpoint === null) return json(response);
if (endpoint === null) return json({ success: false } as APIResponse);
formData.delete('endpoint');
const api_call = await fetch(`http://localhost:8080/${endpoint}`, {