Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
with:
lint: true
license-check: true
40 changes: 0 additions & 40 deletions index.d.ts

This file was deleted.

6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const isCompressedDefault = (res) => {
const contentEncoding = res.headers['content-encoding'] || res.headers['Content-Encoding']
return contentEncoding && contentEncoding !== 'identity'
Expand Down Expand Up @@ -91,7 +93,7 @@ module.exports = (app, options) => {

// API gateway v2 cookies: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
if (event.cookies && event.cookies.length) {
headers['cookie'] = event.cookies.join(';')
headers.cookie = event.cookies.join(';')
}

const prom = new Promise((resolve) => {
Expand Down Expand Up @@ -149,3 +151,5 @@ module.exports = (app, options) => {
return prom
}
}
module.exports.default = module.exports
module.exports.awsLambdaFastify = module.exports
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
"license": "MIT",
"version": "3.1.3",
"main": "index.js",
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint .",
"test": "npm run lint && tap -J -R specy --no-coverage test/*test.js && npm run test:typescript",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap -J -R specy --no-coverage test/*test.js",
"test:typescript": "tsd",
"performance": "npm run lint && node performanceTest/test"
},
"devDependencies": {
"@fastify/multipart": "7.3.0",
"@fastify/pre-commit": "^2.0.2",
"@types/aws-lambda": "8.10.109",
"aws-lambda": "^1.0.7",
"aws-serverless-express": "^3.4.0",
Expand All @@ -59,5 +62,9 @@
},
"publishConfig": {
"access": "public"
}
},
"pre-commit": [
"lint",
"test"
]
}
4 changes: 3 additions & 1 deletion performanceTest/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const Benchmark = require('benchmark')
const suite = new Benchmark.Suite()

Expand Down Expand Up @@ -69,6 +71,6 @@ suite
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
process.exit(0)
process.exit(0) // eslint-disable-line no-process-exit
})
.run({ async: true })
2 changes: 2 additions & 0 deletions test/alb.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { test } = require('tap')
const fastify = require('fastify')
const awsLambdaFastify = require('../index')
Expand Down
6 changes: 4 additions & 2 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { promisify } = require('util')
const { test } = require('tap')
const fastify = require('fastify')
Expand All @@ -20,7 +22,7 @@ test('GET', async (t) => {
}
app.get('/test', async (request, reply) => {
t.equal(request.headers['x-my-header'], 'wuuusaaa')
t.equal(request.headers['cookie'], 'foo=bar')
t.equal(request.headers.cookie, 'foo=bar')
t.equal(request.headers['x-apigateway-event'], '%7B%22version%22%3A%222.0%22%2C%22httpMethod%22%3A%22GET%22%2C%22path%22%3A%22%2Ftest%22%2C%22headers%22%3A%7B%22X-My-Header%22%3A%22wuuusaaa%22%7D%2C%22cookies%22%3A%5B%22foo%3Dbar%22%5D%2C%22queryStringParameters%22%3A%22%22%7D')
t.equal(request.awsLambda.event, evt)
t.equal(request.headers['user-agent'], 'lightMyRequest')
Expand Down Expand Up @@ -405,7 +407,7 @@ test('with existing onRequest hook', async (t) => {
})
app.get('/test', async (request, reply) => {
t.equal(request.headers['x-my-header'], 'wuuusaaa')
t.equal(request.headers['cookie'], 'foo=bar')
t.equal(request.headers.cookie, 'foo=bar')
t.equal(request.awsLambda.event, evt)
t.equal(request.headers['user-agent'], 'lightMyRequest')
t.equal(request.headers.host, 'localhost:80')
Expand Down
2 changes: 2 additions & 0 deletions test/multipart.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const { test } = require('tap')
const fastify = require('fastify')
const awsLambdaFastify = require('../index')
Expand Down
49 changes: 49 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Context } from "aws-lambda";
import { FastifyInstance, LightMyRequestResponse } from "fastify";

type AwsLambdaFastify = typeof awsLambdaFastify

declare namespace awsLambdaFastify {
export interface LambdaFastifyOptions {
binaryMimeTypes?: string[];
callbackWaitsForEmptyEventLoop?: boolean;
serializeLambdaArguments?: boolean;
decorateRequest?: boolean;
decorationPropertyName?: string;
enforceBase64?: (response: LightMyRequestResponse) => boolean;
}

export interface LambdaResponse {
statusCode: number;
body: string;
headers: Record<string, string>;
isBase64Encoded: boolean;
cookies?: string[]
}

export type PromiseHandler<TEvent = any, TResult = LambdaResponse> = (
event: TEvent,
context: Context
) => Promise<TResult>;

export type CallbackHandler<TEvent = any, TResult = LambdaResponse> = (
event: TEvent,
context: Context,
callback: (err?: Error, result?: TResult) => void
) => void;

export const awsLambdaFastify: AwsLambdaFastify
export { awsLambdaFastify as default }
}

declare function awsLambdaFastify<TEvent, TResult = awsLambdaFastify.LambdaResponse>(
app: FastifyInstance,
options?: awsLambdaFastify.LambdaFastifyOptions
): awsLambdaFastify.PromiseHandler<TEvent, TResult>;

declare function awsLambdaFastify<TEvent, TResult = awsLambdaFastify.LambdaResponse>(
app: FastifyInstance,
options?: awsLambdaFastify.LambdaFastifyOptions
): awsLambdaFastify.CallbackHandler<TEvent, TResult>;

export = awsLambdaFastify
2 changes: 1 addition & 1 deletion index.test-d.ts → types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import awsLambdaFastify, {
CallbackHandler,
LambdaFastifyOptions,
LambdaResponse,
} from ".";
} from "..";

import { expectType, expectError, expectAssignable } from "tsd";

Expand Down