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

URL routing? #32

Open
AlecTaylor opened this issue Dec 28, 2013 · 3 comments
Open

URL routing? #32

AlecTaylor opened this issue Dec 28, 2013 · 3 comments

Comments

@AlecTaylor
Copy link

How do I work with URL routing in node.native?

E.g.: I want to expose /foo/ and /bar/ to echo different things.

@jeremieca
Copy link

You must implement your own routing system.
In your server handler you have access to the informations about the request (request& req).
With a simple "if" condition on the request url you'll be able to echo different things.

@AlecTaylor
Copy link
Author

Hmm, is there a trick to printing the request URL?

I've tried:

std::cout << "req = " << req;

And:

std::cout << "req = " << std::string(req);

EDIT: Oh, native::http::request::~request() is private.

EDIT2: I can see the route by returning: res.end(req.url().path());, however neither req.url().path() == "/foo" nor strcmp(req.url().path(), "foo") are working. How do I construct the condition? - Or do I need to construct my own url_obj?

@tclamb
Copy link

tclamb commented Dec 29, 2013

That's really strange. req.url().path() == "/foo" should work.

Try playing with this gist to figure out how to route the way you want: https://gist.github.com/tclamb/8172136

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

3 participants