diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000..3c405f4 --- /dev/null +++ b/.env.local.example @@ -0,0 +1 @@ +BACKEND_URL= \ No newline at end of file diff --git a/src/routes/api/[...path]/index.tsx b/src/routes/api/[...path]/index.tsx index 5370287..285055d 100644 --- a/src/routes/api/[...path]/index.tsx +++ b/src/routes/api/[...path]/index.tsx @@ -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 = {