Fastify
A small notes API, with its Dotpress routes mounted on an existing Fastify instance, and served by Node.js or by AWS Lambda:
- Dotpress routes next to a native Fastify route (
/health), with a Fastify hook applied to both; - one app, two entries:
server.tsfor Node.js,lambda.tsfor AWS Lambda; - tests with
inject()of Fastify, over HTTP, and on simulated API Gateway events, without an AWS account.
Source: examples/fastify.
Run it
The routes
The routes receive their store as an argument, and know nothing about the server:
The app
The Fastify instance keeps its own routes and hooks: beforeRoutes registers what must also apply to the Dotpress routes.
Two entries
On Node.js, the server closes gracefully on SIGTERM:
On AWS Lambda, the same app, created at the first invocation:
npm run build:lambda bundles the handler with esbuild into dist/lambda.mjs, about 300 kB gzipped with Fastify. Fastify is a CommonJS package: the script defines require for it. See Bundle the handler and Deployment › AWS Lambda.