remove hardcoding in proxy

This commit is contained in:
grngxd 2025-08-01 13:08:23 +01:00
parent 3905155ab7
commit 8860f4a5ac
2 changed files with 9 additions and 2 deletions

1
.env.local.example Normal file
View file

@ -0,0 +1 @@
BACKEND_URL=

View file

@ -1,7 +1,13 @@
import type { RequestEvent, RequestHandler } from '@builder.io/qwik-city';
const proxy = async ({ send, url, pathname, request }: RequestEvent) => {
const targetUrl = new URL(`http://localhost:8081${pathname}${url.search}`, url);
const proxy = async ({ send, url, pathname, request, env }: RequestEvent) => {
const backend = env.get("BACKEND_URI")
if (!backend) {
send(new Response("backend uri is not configured in .env.local", { status: 500 }));
return;
}
const targetUrl = new URL(`${backend}${pathname}${url.search}`, url);
const headers = new Headers(request.headers);
const fetchOptions: RequestInit = {