remove hardcoding in proxy
This commit is contained in:
parent
3905155ab7
commit
8860f4a5ac
2 changed files with 9 additions and 2 deletions
1
.env.local.example
Normal file
1
.env.local.example
Normal file
|
@ -0,0 +1 @@
|
|||
BACKEND_URL=
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue