-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-utils): uses host header and mocks waitUntil() (#244)
* feat(node-utils): uses incoming host header to determine request's origin * feat(node-utils): provides mocked fetch event which throws on waitUntil accesses * fix(ci): reverts failing version bump for jest * chore(ci): fixes poisoned turbo cache?
- Loading branch information
Showing
15 changed files
with
629 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@edge-runtime/node-utils': major | ||
--- | ||
|
||
Provides mocked fetch event which throws when using `waitUntil`. `buildToNodeHandler()`'s dependencies now requires `FetchEvent` constructor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@edge-runtime/node-utils': major | ||
--- | ||
|
||
Uses host header as request origin when available. `buildToNodeHandler()`'s `origin` option has been renamed into `defaultOrigin`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Request } from '@edge-runtime/primitives' | ||
import { BuildDependencies } from '../types' | ||
|
||
export function buildToFetchEvent(dependencies: BuildDependencies) { | ||
return function toFetchEvent(request: Request) { | ||
const event = new dependencies.FetchEvent(request) | ||
Object.defineProperty(event, 'waitUntil', { | ||
configurable: false, | ||
enumerable: true, | ||
get: () => { | ||
throw new Error('waitUntil is not supported yet.') | ||
}, | ||
}) | ||
return event | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './fetch-event' | ||
export * from './headers' | ||
export * from './request' | ||
export * from './stream' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as EdgeRuntime from '@edge-runtime/primitives' | ||
import { buildToFetchEvent } from '../../src' | ||
|
||
const toFetchEvent = buildToFetchEvent({ | ||
Headers: EdgeRuntime.Headers, | ||
ReadableStream: EdgeRuntime.ReadableStream, | ||
Request: EdgeRuntime.Request, | ||
Uint8Array: Uint8Array, | ||
FetchEvent: EdgeRuntime.FetchEvent, | ||
}) | ||
|
||
it('returns a fetch event with a request', () => { | ||
const request = new EdgeRuntime.Request('https://vercel.com') | ||
const event = toFetchEvent(request) | ||
expect(event).toBeInstanceOf(EdgeRuntime.FetchEvent) | ||
expect(event.request).toBe(request) | ||
}) | ||
|
||
it('throws when accessing waitUntil', () => { | ||
const request = new EdgeRuntime.Request('https://vercel.com') | ||
const event = toFetchEvent(request) | ||
expect(() => event.waitUntil(Promise.resolve())).toThrow( | ||
'waitUntil is not supported yet.' | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7110a53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
edge-runtime – ./
edge-runtime-git-main.vercel.sh
edge-runtime.vercel.sh
edge-runtime.vercel.app