-
Notifications
You must be signed in to change notification settings - Fork 84
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
Request not found on '/' ended urls #188
Comments
Hi, the reason why In this scenario, I would recommend adding code in your not found handler to redirect requests ending in trail slashes to their non trail slash counter parts. Something like below would be a start: server.set_not_found_handler((request, response) => {
// Redirect requests ending in trail slashes to non trail slash URL
if (request.path.endsWith('/')) {
// Remove the trailing slash from the path of the URL
const non_trail_slash_url = request.url.replace(request.path, request.path.substring(0, request.path.length - 1));
// Redirect the request to the non trailing slash URL
return response.redirect(non_trail_slash_url);
}
}); |
@kartikk221 Does the response.redirect send 301 status to client? |
The hyper-express/src/components/http/Response.js Lines 698 to 706 in 0100dd0
Yeah, the best approach would be to remove the trail slash before route mapping and then internally route the requests but the problem is it would be a breaking change for the current version and something that will be kept in consideration for the next major version. |
I think it's better to keep the same behavior and provide an option to let the user decide whether the trail slash would be removed or not. |
Hi @kartikk221
![image](https://private-user-images.githubusercontent.com/32927231/269756206-f7b8776a-064a-4e2a-8f2d-9bfd2df12733.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNDA0MTUsIm5iZiI6MTcyMTM0MDExNSwicGF0aCI6Ii8zMjkyNzIzMS8yNjk3NTYyMDYtZjdiODc3NmEtMDY0YS00ZTJhLThmMmQtOWJmZDJkZjEyNzMzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDIyMDE1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdlZWFmMmU5ZjJmZjAzNmQ3OGU3Y2M3MGMxYjAwNDA1YzRlYmI5MjQzODJkOGYxYTNiZDc2MGE2NjU2OTgwODkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.o25YHs2q4dnLw2KCCxjsttBgxb22_x3LrI3X4TvIFOY)
I was working on my API and I created a router with this structure:
And when I checked the Rest Client for
http://localhost:5000/api/v1
I got the response but forhttp://localhost:5000/api/v1/
I got "Not Found".is there any option in hyper-express server to fix this or not?
this is my server object:
![image](https://private-user-images.githubusercontent.com/32927231/269756773-187ee67d-f245-45fd-be49-bbc65f8ecfcd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNDA0MTUsIm5iZiI6MTcyMTM0MDExNSwicGF0aCI6Ii8zMjkyNzIzMS8yNjk3NTY3NzMtMTg3ZWU2N2QtZjI0NS00NWZkLWJlNDktYmJjNjVmOGVjZmNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDIyMDE1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc4MDFkOWFhOWQ1Njg0ZDBjMjM5ZGIwMmRjNjMxM2E2NzI2MGFjNWNjZGUxNjU5ZDI5NGMwMTc0MWVkMDYxMjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.EThb0nvEB-IaTXoIjLUYsHwEL_h0Kf3uitDpiVmJPW8)
and these are the responses from the Rest Client:
![image](https://private-user-images.githubusercontent.com/32927231/269756917-0b275bed-85f9-451f-9a50-cd7bcebfc0de.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNDA0MTUsIm5iZiI6MTcyMTM0MDExNSwicGF0aCI6Ii8zMjkyNzIzMS8yNjk3NTY5MTctMGIyNzViZWQtODVmOS00NTFmLTlhNTAtY2Q3YmNlYmZjMGRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDIyMDE1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdiOTE1NjYwMjQ5YzE3MWI3YzE2MTJmYzgzMTE4ZWViNmQyYTE4NjMwODI2ZTQ3ZWQ4MTAxODg2NDJjZDM5ZmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.O-mliBJZwOSEVZJvf1k5jkreFY5XAF5rYRdTZREZeG0)
![image](https://private-user-images.githubusercontent.com/32927231/269756962-543f0e89-bf71-4b55-8091-632ddd8c44a8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNDA0MTUsIm5iZiI6MTcyMTM0MDExNSwicGF0aCI6Ii8zMjkyNzIzMS8yNjk3NTY5NjItNTQzZjBlODktYmY3MS00YjU1LTgwOTEtNjMyZGRkOGM0NGE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDIyMDE1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVhMTkwZWQzYmZlNmQ1OGViMzNjODZjZDdhNzAwZTMzZGZmYzBmMzM2NWQ0ZTRiODE0MmY5ZWNjYjc5YzE5YjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FzMgpNPv_SrTK2nxFQiQbuYmHlxQ3Sq78jEk7yhJ-5Y)
The text was updated successfully, but these errors were encountered: