node.native icon indicating copy to clipboard operation
node.native copied to clipboard

URL routing?

Open AlecTaylor opened this issue 11 years ago • 3 comments

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

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

AlecTaylor avatar Dec 28 '13 13:12 AlecTaylor

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.

jeremieca avatar Dec 28 '13 14:12 jeremieca

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?

AlecTaylor avatar Dec 29 '13 08:12 AlecTaylor

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

tclamb avatar Dec 29 '13 16:12 tclamb