From 247c2fea7da38c685d4bc943061384bb9538e90a Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 18 Aug 2025 16:36:45 +0300 Subject: [PATCH 1/4] Update docs This might also apply to the similar @fastify/express --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 959d264..137696b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ *@fastify/middie* is the plugin that adds middleware support on steroids to [Fastify](https://www.npmjs.com/package/fastify). -The syntax style is the same as [express](http://npm.im/express)/[connect](https://www.npmjs.com/package/connect). +The syntax style is the same as [connect](https://www.npmjs.com/package/connect). +But it does not provide full compatbility with [express](http://npm.im/express) which has its own extended request/response objects, see [@fastify/express] if that is needed. Does not support the full syntax `middleware(err, req, res, next)`, because error handling is done inside Fastify. ## Install @@ -157,6 +158,29 @@ async function subsystem (fastify, opts) { // Multiple paths fastify.use(['/css', '/js'], serveStatic(path.join(__dirname, '/assets'))) + + // Catch all routes so that Fastify will call the middlewares above + fastify.all('/css', () => {}) + fastify.all('/css/*', () => {}) + fastify.all('/js', () => {}) +} +``` + +### Usage with middlewares that act as routes +A middleware that is designed to act as a route handler rather than wrap existing routes will require a catch all route in Fastify so that the middleware gets called. + +```js +const fastify = require('fastify')() + +fastify + .register(require('@fastify/middie')) + .register(subsystem) + +async function subsystem (fastify, opts) { + fastify.use(serveStatic(path.join(__dirname, '/assets'))) + + // Catch all routes so that Fastify will call the middleware above + fastify.all('*', () => {}) } ``` From 367c7cce6c9ef4930c79fc7fc2a7b0eab8087fe8 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 18 Aug 2025 23:23:50 +0300 Subject: [PATCH 2/4] Update README.md Signed-off-by: Segev Finer --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 137696b..541ba2e 100644 --- a/README.md +++ b/README.md @@ -160,9 +160,15 @@ async function subsystem (fastify, opts) { fastify.use(['/css', '/js'], serveStatic(path.join(__dirname, '/assets'))) // Catch all routes so that Fastify will call the middlewares above - fastify.all('/css', () => {}) - fastify.all('/css/*', () => {}) - fastify.all('/js', () => {}) + fastify.all('/css', () => { + return reply + }) + fastify.all('/css/*', () => { + return reply + }) + fastify.all('/js', () => { + return reply + }) } ``` @@ -179,8 +185,10 @@ fastify async function subsystem (fastify, opts) { fastify.use(serveStatic(path.join(__dirname, '/assets'))) - // Catch all routes so that Fastify will call the middleware above - fastify.all('*', () => {}) + // Catch all route so that Fastify will call the middleware above + fastify.all('*', () => { + return reply + }) } ``` From 562f036443b6fa870a9dc390b8d5f3b9424f889b Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 10 Nov 2025 13:58:05 +0200 Subject: [PATCH 3/4] Fix missing reply parameter Signed-off-by: Segev Finer --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 541ba2e..2f15844 100644 --- a/README.md +++ b/README.md @@ -160,13 +160,13 @@ async function subsystem (fastify, opts) { fastify.use(['/css', '/js'], serveStatic(path.join(__dirname, '/assets'))) // Catch all routes so that Fastify will call the middlewares above - fastify.all('/css', () => { + fastify.all('/css', (request, reply) => { return reply }) - fastify.all('/css/*', () => { + fastify.all('/css/*', (request, reply) => { return reply }) - fastify.all('/js', () => { + fastify.all('/js', (request, reply) => { return reply }) } From 8899ddf1c284b5bb5c2feb67cce82b676b7b8316 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 11 Nov 2025 18:11:12 +0200 Subject: [PATCH 4/4] Update README.md Co-authored-by: Manuel Spigolon Signed-off-by: Segev Finer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f15844..1a776d9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ *@fastify/middie* is the plugin that adds middleware support on steroids to [Fastify](https://www.npmjs.com/package/fastify). The syntax style is the same as [connect](https://www.npmjs.com/package/connect). -But it does not provide full compatbility with [express](http://npm.im/express) which has its own extended request/response objects, see [@fastify/express] if that is needed. +But it does not provide full compatbility with [express](http://npm.im/express) which has its own extended request/response objects, see [@fastify/express](https://github.com/fastify/fastify-express) if that is needed. Does not support the full syntax `middleware(err, req, res, next)`, because error handling is done inside Fastify. ## Install