All files / src/worker/utils origin.ts

27.27% Statements 3/11
50% Branches 1/2
100% Functions 1/1
27.27% Lines 3/11

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  29x   29x                                   29x    
export function fetchOrigin(request: Request) {
  const origin = import.meta.env.VITE_ORIGIN
 
  Iif (origin) {
    const originUrl = new URL(origin)
    const requestUrl = new URL(request.url)
 
    originUrl.pathname = requestUrl.pathname
    originUrl.search = requestUrl.search
    const headers = new Headers(request.headers)
    headers.set('Host', originUrl.host)
 
    console.log(`Using local override: ${originUrl}`)
    return fetch(originUrl, {
      //duplex: 'half', // The CF types don't support duplex right now but wrangler needs it locally
      headers,
      method: request.method,
      body: request.body,
    })
  }
 
  return fetch(request)
}