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

Issue with trailing slash redirect #89

Open
faizan-glitch opened this issue Apr 19, 2023 · 3 comments
Open

Issue with trailing slash redirect #89

faizan-glitch opened this issue Apr 19, 2023 · 3 comments

Comments

@faizan-glitch
Copy link

faizan-glitch commented Apr 19, 2023

BunRouter is redirecting a POST request without a trailing to the GET Handler

I have the following code
image

If i send a POST request to /accounts/ then it works perfectly fine
But if send a POST request to /accounts then it redirects to GET /accounts
I have attached some screenshots below
As it can be seen that it works fine if i have a trailing slash
image

but if I remove the trailing slash I get this
image

Notice how I get method not allowed that is because I am getting redirected to a GET handler for /accounts/ which doesn't exists
image

POST Request to /accounts should get redirected to POST handler of /accounts/ instead of GET handler of /accounts

P.S: I am using bunrouter v1.0.20

@faizan-glitch faizan-glitch changed the title Issue with trailing / redirect Issue with trailing slash redirect Apr 19, 2023
@aikchun
Copy link

aikchun commented Apr 21, 2023

@faizan-glitch For this case, you can just omit the slash.

router.WithGroup("/accounts", func(g *bunrouter.CompatGroup) {
    // g.POST("/", accountHandler.Signup)
    g.POST("", accountHandler.Signup)
}

Like this.
Of course, this present the issue with that if you were to request POST - /accounts/ you will still get GET - /accounts/

@faizan-glitch
Copy link
Author

@aikchun yes, i realize that i can omit the trailing slash, but that is not the expected behaviour, because I cannot make sure that the frontend devs will always omit it.

As of now I have added two seperate routes, one with the trailing slash another without the trailing slash to get around this. but it is very weird.

is there any particular reason why Bunrouter by default redirects towards GET instead of whatever is the correct HTTP method?

@aikchun
Copy link

aikchun commented Apr 26, 2023

is there any particular reason why Bunrouter by default redirects towards GET instead of whatever is the correct HTTP method?

I am not sure myself. I was looking to contribute to the project through your issue so I am kinda new to the project and contributing to OSS in general. It does seem like it is handling trailing slashes in a way, I'm just not sure how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants