-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
108 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
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,40 @@ | ||
import { AsyncLocalStorage } from "node:async_hooks"; | ||
import { | ||
APIGatewayProxyEvent, | ||
APIGatewayProxyEventV2, | ||
APIGatewayProxyStructuredResultV2, | ||
Context, | ||
} from "aws-lambda"; | ||
import { Hono } from "hono"; | ||
import { handle } from "hono/aws-lambda"; | ||
|
||
export type APIGatewayInput = { | ||
event: APIGatewayProxyEventV2 | APIGatewayProxyEvent; | ||
context: Context; | ||
}; | ||
|
||
export const asyncLocalStorage = new AsyncLocalStorage<APIGatewayInput>(); | ||
|
||
export function getAPIGatewayInput(): APIGatewayInput | undefined { | ||
return asyncLocalStorage.getStore(); | ||
} | ||
|
||
export const wrap_apigateway = (app: Hono) => { | ||
const handle_core = handle(app); | ||
|
||
return async ( | ||
event: APIGatewayProxyEventV2 | APIGatewayProxyEvent, | ||
context: Context, | ||
): Promise<APIGatewayProxyStructuredResultV2> => { | ||
const apigw: APIGatewayInput = { | ||
event, | ||
context, | ||
}; | ||
|
||
const response = await asyncLocalStorage.run(apigw, async () => { | ||
return await handle_core(event as any); | ||
}); | ||
|
||
return response; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.