-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fastify + middleware wildcards #972
Comments
I cannot reproduce your issue. Check your |
Sorry, I realized it was because of the FastifyAdapter, for some reason no path argument works when you're the fastifyAdapter, do you treat middleware rules differently using Fastify? I also noticed res.send() doesn't work in the middleware, I presume that works differently as well. Thanks for the quick reply! |
Fixed in #975. Will be available in |
5.2.0 is here! |
Hi @kamilmysliwiec, I have installed 5.2.2 and however I cannot get our authentication middleware to run using either of the following - .forRoutes({ path: '', method: RequestMethod.ALL } ); For express it worked using Are you able to provide an example? |
Hello @kamilmysliwiec I tried both functional and NestMiddleware, both of them not working with fastify adapter and no error is thrown. If i remove fastify adapter and use express (which is default) middlewares work as expected. Even without |
Hi @kamilmysliwiec, I am trying Fastify again I still cannot get Middleware to run for a wildcard route. Are you able to please advise or show us an example where the following will work - return consumer The middleware never gets called. Been stuck over and over again. Either we are missing something or something is broken. Regards, "@nestjs/common": "5.6.2", |
Same here! NestJs 5.6.2. In Fastify is not working, when i switch to Express, it works! |
For me it's not working when I have query params in the request:
The middleware is configured so it works for all the endpoints of the controller: configure(consumer: MiddlewareConsumer) {
consumer
.apply(UserMiddleware)
.forRoutes(MyController)
}
|
i am having this problem too, using nest version: 5.4.0 is this solved yet? |
Fixed in 5.7.2 :) |
Currently using v5.7.3 and this doesn't seem to be fixed. I have a very simple middleware set to |
@Tsury could you send me a github repository URL? I'll check out locally |
Yes, I'll make some temp repo and link here. |
It should be fixed in 5.7.4 |
@kamilmysliwiec it was not repaired at [email protected], //some api : /v1/get/1
.forRoutes('/'); // fastify is not ok,
.forRoutes('/v1'); // only express is ok,
.forRoutes('/v1'); // only express is ok,
.forRoutes('*'); // fastify & express are ok, |
Hi !
but this doesn't work.
|
For anyone using Fastify trying to solve this issue, one workaround is to check the path within the middleware. Set your routes to the * wildcard:
Then check the URL within the middleware
|
Hi @kamilmysliwiec, We are in the process of moving from express to Fastify and have similar issue with the middleware not running when registering in the module using forRoute('*'). I believe the issue occurs when used in conjunction with setGlobalPrefix. I have attached a simple demo app. The app has a controller and a middleware (it console logs and attaches a user to the request). To test -
To test with global prefix =/api
To test without the global prefix
Middleware Running Middleware Not Running |
So I've just created a plain fastify application: const instance = fastify();
instance.get('/app/test', (res, rep) => {
rep.send('Hello world');
});
instance.use('/app/*', (req, res, next) => {
console.log('request');
next();
});
instance.listen(3001); and it doesn't work either. It seems that this issue isn't related to NestJS, but rather to fastify. |
@kamilmysliwiec in my example above I have no problems with the wildcard middleware running when I don't specify the Global Prefix such as '/api'. To get around the lack of Global Prefix and use nest-router to mount the controllers on /api. |
The reason has been described in this post: #972 (comment) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
I want to catch all requests with a middleware, but using * or / as path when registering the middleware simply does nothing.
Expected behavior
Using this code, or with / as path, or simply '*' as an argument for the "forRoutes"-method, I'd wish to catch all routes with the middleware, it only works if I write e.g. 'cats' as path.
Environment
The text was updated successfully, but these errors were encountered: