( context: Context, route: DevProxyRoute, fetchImpl: typeof globalThis.fetch, allowedOrigins: DevProxyCorsAllowedOrigins, )
| 172 | } |
| 173 | |
| 174 | const proxyRequest = async ( |
| 175 | context: Context, |
| 176 | route: DevProxyRoute, |
| 177 | fetchImpl: typeof globalThis.fetch, |
| 178 | allowedOrigins: DevProxyCorsAllowedOrigins, |
| 179 | ) => { |
| 180 | const requestUrl = new URL(context.req.url) |
| 181 | const targetUrl = buildUpstreamUrl(route.target, requestUrl.pathname, requestUrl.search) |
| 182 | const requestHeaders = createProxyRequestHeaders(context.req.raw, targetUrl, route.cookieRewrite) |
| 183 | const requestInit: RequestInit & { duplex?: 'half' } = { |
| 184 | method: context.req.method, |
| 185 | headers: requestHeaders, |
| 186 | redirect: 'manual', |
| 187 | } |
| 188 | |
| 189 | if (context.req.method !== 'GET' && context.req.method !== 'HEAD') { |
| 190 | requestInit.body = context.req.raw.body |
| 191 | requestInit.duplex = 'half' |
| 192 | } |
| 193 | |
| 194 | const upstreamResponse = await fetchImpl(targetUrl, requestInit) |
| 195 | const responseHeaders = createUpstreamResponseHeaders( |
| 196 | upstreamResponse, |
| 197 | targetUrl, |
| 198 | context.req.header('origin'), |
| 199 | allowedOrigins, |
| 200 | route.cookieRewrite, |
| 201 | ) |
| 202 | |
| 203 | return new Response(upstreamResponse.body, { |
| 204 | status: upstreamResponse.status, |
| 205 | statusText: upstreamResponse.statusText, |
| 206 | headers: responseHeaders, |
| 207 | }) |
| 208 | } |
| 209 | |
| 210 | const normalizeRoutePaths = (paths: DevProxyRoute['paths']) => Array.isArray(paths) ? paths : [paths] |
| 211 |
no test coverage detected