Skip to content

Commit

Permalink
make sure edge function entries are properly awaited (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz authored Jan 20, 2025
1 parent 1981a47 commit e5678b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-carrots-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix: make sure edge function entries are properly awaited
6 changes: 3 additions & 3 deletions packages/open-next/src/core/edgeFunctionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default async function edgeFunctionHandler(
throw new Error(`No route found for ${request.url}`);
}

const result = await self._ENTRIES[
`middleware_${correspondingRoute.name}`
].default({
const entry = await self._ENTRIES[`middleware_${correspondingRoute.name}`];

const result = await entry.default({
page: correspondingRoute.page,
request: {
...request,
Expand Down
14 changes: 8 additions & 6 deletions packages/open-next/src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export interface RequestData {
signal: AbortSignal;
}

interface Entry {
default: (props: { page: string; request: RequestData }) => Promise<{
response: Response;
waitUntil: Promise<void>;
}>;
}

interface Entries {
[k: string]: {
default: (props: { page: string; request: RequestData }) => Promise<{
response: Response;
waitUntil: Promise<void>;
}>;
};
[k: string]: Entry | Promise<Entry>;
}

export interface EdgeRoute {
Expand Down

0 comments on commit e5678b3

Please # to comment.