Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Dec 17, 2023
1 parent ec35546 commit ac766ec
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions src/adapter/aws-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
import { map } from "@raviqqe/loscore";
import { filterValues, isString } from "@raviqqe/loscore";
import {
collectString,
toIterable,
toStringStream,
} from "@raviqqe/loscore/async";
import {
type CloudFrontRequestHandler,
type CloudFrontResultResponse,
} from "aws-lambda";
import { LambdaFunctionURLHandler } from "aws-lambda";

Check failure on line 7 in src/adapter/aws-lambda.ts

View workflow job for this annotation

GitHub Actions / test

All imports in the declaration are only used as types. Use `import type`
import { type RequestHandler } from "../main.js";

export const awsLambda =
(handler: RequestHandler): CloudFrontRequestHandler =>
async ({ Records: [record] }) => {
if (!record) {
throw new Error("Invalid record in CloudFront event");
}

const { request } = record.cf;

const headers = new Headers();

for (const [key, values] of Object.entries(request.headers)) {
for (const value of values) {
headers.append(key, value.value);
}
}
(handler: RequestHandler): LambdaFunctionURLHandler =>
async (request) => {
console.log(request.requestContext.http);

Check failure on line 13 in src/adapter/aws-lambda.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

const response = await handler(
new Request(new URL(request.uri), {
body: request.body?.data,
headers,
method: request.method,
new Request(new URL(request.requestContext.http.path), {
body: request.body,
headers: new Headers(filterValues(request.headers, isString)),
method: request.requestContext.http.method,
}),
);

return {
body: response.body
? await collectString(toIterable(toStringStream(response.body)))
: undefined,
headers: Object.fromEntries(
map(response.headers.entries(), ([key, value]) => [key, [{ value }]]),
),
headers: Object.fromEntries(response.headers.entries()),
status: response.status.toString(),
} satisfies CloudFrontResultResponse;
};
};

0 comments on commit ac766ec

Please sign in to comment.