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

A method to test a string against the routes table #2220

Closed
briandela opened this issue Nov 27, 2014 · 5 comments
Closed

A method to test a string against the routes table #2220

briandela opened this issue Nov 27, 2014 · 5 comments
Assignees
Labels
Milestone

Comments

@briandela
Copy link
Contributor

@briandela briandela commented Nov 27, 2014

Just wondering if there is a way in 7.5.x to check if a string would be a valid match for one of the routes.

In a location where I have access to the server object I have a string (e.g. /hello/there/hapi) and I want to see if it would match a route in that server object (e.g. if there was a /hello/there/{thing} the above string would match that (assuming that was the best match)).

Thanks.

@gergoerdosi
Copy link
Contributor

@gergoerdosi gergoerdosi commented Nov 27, 2014

Depending on what your handler is doing, you could call server.inject('/hello/there/hapi', function (res) { }). If it returns 2xx, then the route exists, if it returns 404, then it doesn't. Of course the handler can return 404 for other reasons too (like document doesn't exist in the database). That's why this depends on what your handler is doing.

An other way could be to call server.table() to get the array of routes:
https://github.com/hapijs/hapi/blob/v7.5.2/docs/Reference.md#servertablehost

You could then create a Call object, add the routes returned by server.table() and test your routes with the route() function:
https://github.com/hapijs/call/blob/fc7978b19fb068c2e7dfd5c00fbbd1f52eee163f/lib/index.js#L88

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Nov 27, 2014

Not directly. The above suggestions are your only real option. There used to be an internal method to do that but it's not longer available.

@briandela
Copy link
Contributor Author

@briandela briandela commented Nov 27, 2014

Thanks all.
@hueniverse We'll be moving to 8 in the near future. Is there an alternative way of doing this with v8?

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Nov 27, 2014

I am thinking about adding this feature, hence why this issue is still open...

@hueniverse hueniverse changed the title Hapi 7.5.x: Is there a way to test a string against the routes table A method to test a string against the routes table Nov 28, 2014
@hueniverse hueniverse added this to the 8.0.0 milestone Nov 30, 2014
@hueniverse hueniverse self-assigned this Nov 30, 2014
@Marsup Marsup added feature and removed request labels Sep 20, 2019
@lock
Copy link

@lock lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants