Skip to content

Commit

Permalink
Merge pull request #3 from WitoDelnat/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Oct 22, 2024
2 parents d1132e1 + 7d6494b commit 2bf2643
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export function connectWorkersAdapter<Env = unknown, CfHostMetadata = unknown>(
const handler = paths.get(new URL(request.url).pathname)
if (!handler) return options.fallback ? options.fallback(request, env, context) : notFoundResponse

const universalRequest: UniversalServerRequest = requestToUniversalRequest(request)
const contextValues = options.contextValues?.(request, env, context)
const universalRequest: UniversalServerRequest = requestToUniversalRequest(request, contextValues)
const universalResponse = await handler(universalRequest)

return universalResponseToResponse(universalResponse)
Expand All @@ -78,7 +79,7 @@ export function connectWorkersAdapter<Env = unknown, CfHostMetadata = unknown>(

// Utils **********************************************************************

function requestToUniversalRequest(request: Request): UniversalServerRequest {
function requestToUniversalRequest(request: Request, contextValues?: ContextValues): UniversalServerRequest {
const httpVersion = request.cf?.httpProtocol === 'HTTP/2' ? '2.0' : '1.1'
return {
httpVersion: httpVersion,
Expand All @@ -87,6 +88,7 @@ function requestToUniversalRequest(request: Request): UniversalServerRequest {
header: request.headers,
body: request.body,
signal: request.signal,
contextValues,
}
}

Expand Down

0 comments on commit 2bf2643

Please sign in to comment.