Skip to content
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

404 when passing more than 1 middleware to app.method #22

Closed
theoparis opened this issue Jul 16, 2020 · 12 comments
Closed

404 when passing more than 1 middleware to app.method #22

theoparis opened this issue Jul 16, 2020 · 12 comments
Labels
bug Something isn't working core Affects `@tinyhttp/app` - the tinyhttp core

Comments

@theoparis
Copy link

Sooooo,
I am having a new issue: the first response gives an actual error/result (which is expected), but on the second request it responds with my 404 noMatchHandler.. It doesn't matteer what the url is on the second request, it just sends the 404 and then complains the headers are already sent.

@theoparis theoparis added the bug Something isn't working label Jul 16, 2020
@talentlessguy
Copy link
Member

@creepinson once again I will need a reproducible demo :)

@talentlessguy talentlessguy added the needs reproduction Needs a reproduction demo / repository to investigate further label Jul 16, 2020
@theoparis
Copy link
Author

theoparis commented Jul 17, 2020

Oof, I installed the latest version of @tinyhttp/app and got this on almost every page except for /profile....
image

/ should at least be found here but its not anymore
heres the code: https://hastebin.com/jaxefuqapo.coffeescript

@talentlessguy
Copy link
Member

@creepinson interesting, there is some external module made by you. Could you please make a route-only demo that I can try?

Also, body-parser doesn't work. See #25

@talentlessguy
Copy link
Member

@creepinson is it still relevant?

@talentlessguy
Copy link
Member

I'm not sure if it is still relevant, so closing

feel free to re-open if it persists

@theoparis
Copy link
Author

theoparis commented Jul 27, 2020

Ok, well I'm still getting a 404 error and it seems to be with using multiple middlewares like so:

My "test" middleware:

async function test(req: Request, res: Response, next?: NextFunction) {
	console.log(`req body: ${JSON.stringify(req.body)}`);
	next!();
}

Then I use it like so:

app.post('/register', test, register);

where the test middleware is supposed to be executed and then after it is called my register middleware in the rest of my code gets called. While it does execute the test middleware and prints out the request body, it then gives the following from the logger middleware:
POST 404 Not Found /register
even though it just worked with the first test middleware.

I will try and make a reproducable demo as well.

@theoparis
Copy link
Author

theoparis commented Jul 27, 2020

Ok, I've managed to create a simple demo: https://github.com/creepinson/tinyhttp-example/blob/master/src/index.ts

Incorrrect output from the demo:

Listening on :8080
Req url: "/test"
GET 404 Not Found /test

which gives my 404 response back to the curl command.

What should be logged:

Listening on :8080
Req url: "/test"
GET 200 OK /test

and the response should be a json object that was specified in the code.

@theoparis
Copy link
Author

theoparis commented Jul 27, 2020

I don't think I can reopen this issue manually, I think you have to do it for me because you are the one that closed the issue.

@talentlessguy
Copy link
Member

@creepinson, OK reoping

I won't be able to help ya for ~2 weeks so pls be patient :)

@talentlessguy talentlessguy reopened this Jul 28, 2020
@talentlessguy
Copy link
Member

Ok, I'm back here

the issue comes from when there are more than 1 wares passed to app.method

will look into this very soon

@talentlessguy talentlessguy changed the title 404 being sent on second request. 404 when passing more than 1 middleware to app.method Aug 7, 2020
@talentlessguy talentlessguy added core Affects `@tinyhttp/app` - the tinyhttp core and removed needs reproduction Needs a reproduction demo / repository to investigate further labels Aug 7, 2020
@talentlessguy
Copy link
Member

@theoparis
Copy link
Author

seems to be working with my small example :D
I will also try my larger example but I think it might be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Affects `@tinyhttp/app` - the tinyhttp core
Projects
None yet
Development

No branches or pull requests

2 participants