fix(lambda-edge) Adding Export Type CloudFrontResponse and CloudFrontConfig (#1263)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* export type * revert
authored by watany · committed by GitHub · parent 84973c9 · Browse files · 3 files·+54 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+54 added−3 removed
- tests:+51 added−1 removed
- other:+3 added−2 removed
Provenance
- Commit
cbd5616- Tree
0e7ea34- Author
watany <76135106+watany-dev@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
84973c9
3 files changed+54 added−3 removed
modified:runtime_tests/lambda-edge/index.test.ts+51 added-1 removed
1 /* eslint-disable quotes */2-import type { Callback, CloudFrontRequest, CloudFrontResponse } from '../../src/adapter/lambda-edge/handler'2+import type { Callback, CloudFrontConfig, CloudFrontRequest, CloudFrontResponse } from '../../src/adapter/lambda-edge/handler'3 import { handle } from '../../src/adapter/lambda-edge/handler'4 import { Hono } from '../../src/hono'5 import { basicAuth } from '../../src/middleware/basic-auth'6 7 type Bindings = {8 callback: Callback9+ config: CloudFrontConfig10 request: CloudFrontRequest11 response: CloudFrontResponse12 }13 19 unmodified lines33 await next()34 c.env.callback(null, c.env.request)35 })36 37+ app.get('/config/eventCheck', async (c, next) => {38+ await next()39+ if(c.env.config.eventType in ['viewer-request', 'origin-request']) {40+ c.env.callback(null, c.env.request)41+ } else {42+ c.env.callback(null, c.env.response)43+ }44+ })45+46 app.get('/callback/response', async (c, next) => {47 await next()48 c.env.callback(null, c.env.response)49 })994 unmodified lines1044 value: "Foo"1045 }1046 ]);1047 })1048+1049+ it('Callback Event (Lambda@Edge response)', async () => {1050+ const event = {1051+ Records: [1052+ {1053+ cf: {1054+ config: {1055+ distributionDomainName: 'example.com',1056+ distributionId: 'EDFDVBD6EXAMPLE',1057+ eventType: 'viewer-response',1058+ requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',1059+ },1060+ request: {1061+ clientIp: '203.0.113.178',1062+ headers: {1063+ host: [1064+ {1065+ key: 'Host',1066+ value: 'example.com',1067+ },1068+ ],1069+ },1070+ method: 'GET',1071+ querystring: '',1072+ uri: '/config/eventCheck',1073+ },1074+ }1075+ },1076+ ],1077+ }1078+ 1079+ let called = false1080+ await handler(event, {}, (_err, result) => {1081+ called = true1082+ })1083+1084+ expect(called).toBe(true)1085+ })1086+1087+1088 })modified:src/adapter/lambda-edge/handler.ts+2 added-1 removed
49 unmodified lines5051525354545556575855 unmodified lines11411511611711811912012112241 unmodified lines49 unmodified lines status: string statusDescription?: string}
interface CloudFrontConfig {export interface CloudFrontConfig { distributionDomainName: string distributionId: string eventType: string requestId: string55 unmodified lines context, callback: (err: Error | null, result?: CloudFrontResult | CloudFrontRequest) => { callback?.(err, result) }, config: event.Records[0].cf.config, request: event.Records[0].cf.request, response: event.Records[0].cf.response, }) return createResult(res)41 unmodified linesmodified:src/adapter/lambda-edge/index.ts+1 added-1 removed
1233// @denoify-ignoreexport { handle } from './handler'export type { Callback, CloudFrontRequest, CloudFrontEdgeEvent } from './handler'export type { Callback, CloudFrontConfig, CloudFrontRequest, CloudFrontResponse, CloudFrontEdgeEvent } from './handler'