2.0.1 • Published 2 years ago
@lamware/fastify v2.0.1
This Lamware Middleware utilizes the official AWS Lambda Fastify Client to provide a convenient, and performant, method of intializing and memoizing Fastify in AWS Lambda:
- Enforces memoization of Fastify Client outside of function handler
- Allow for top-level ready state initialization, perfect for Provisioned Concurrency
Installation
This package is available via NPM:
yarn add @lamware/fastify
# or
npm install @lamware/fastify
Usage
import type { APIGatewayProxyHandlerV2 } from 'aws-lambda';
import type { LamwareState } from '@lamware/core';
import { fastify } from '@lamware/fastify';
import { lamware } from '@lamware/core';
// import createFastify from 'fastify';
const { instance, handler } = lamware<APIGatewayProxyHandlerV2<any>>()
.use(fastify(app => {
// You can provide a closure that exposes the `fastify` instance.
app.get('/', (request, reply) => {
reply.send({ hello: 'world' }));
};
return app;
}, {
// You can optionally provide an existing Fastify client.
// client: createFastify(),
// And also enforce Fastify to ready-up before running.
enforceReady: true,
}))
.execute(async (payload) => {
return payload.state.fastifyHandler(payload);
});
/**
* Fastify doesn't have _great_ flexibility when it comes to typing.
* As a result, you'll have to manually type the state request object.
* For example:
*/
declare module 'fastify' {
interface FastifyRequest {
state: LamwareState<typeof instance>;
}
}
export { handler };
1.2.2
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.2.0
3 years ago
1.2.1
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.21
3 years ago
1.0.20
3 years ago
1.0.19
3 years ago
1.0.18
3 years ago
1.0.17
3 years ago
1.0.16
3 years ago
1.0.15
3 years ago
1.0.14
3 years ago
1.0.13
3 years ago
1.0.12
3 years ago
1.0.11
3 years ago
1.0.10
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago