Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import { ENV } from '@/constants';
/**
* Proxies an incoming request from Astro middleware to the target API endpoint.
*
* @param context - The Astro middleware context containing the original request.
* @param targetPath - The path to append to the API endpoint (e.g., "/rpc" or "/ws").
* @param options - Optional fetch options to override the default request init.
* @returns A Promise resolving to the proxied fetch Response object.
*/
export const proxyRequest = async (
context: any,
targetPath: string,
options?: RequestInit,
) => {
const url = new URL(ENV.API_ENDPOINT + targetPath);
const proxyReq = new Request(url.toString(), {
method: context.request.method,
headers: context.request.headers,
...options,
});
return fetch(proxyReq);
};
|