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

How to route in USP code? #30

Closed
shivshankardayal opened this issue Sep 13, 2017 · 15 comments
Closed

How to route in USP code? #30

shivshankardayal opened this issue Sep 13, 2017 · 15 comments

Comments

@shivshankardayal
Copy link

Consider I have an usp file say one.usp which gives me one.so so that my URL served is http://localhost/one. Now if I want to serve http://localhost/one/two then how can I achieve that?

@victorstewart
Copy link
Collaborator

just create a directory named "one" in your document root directory, and put two.so inside it

@stefanocasazza
Copy link
Owner

Hi,

I think that better than words is a prototype:
one.usp
one.test
one.req

@shivshankardayal
Copy link
Author

Thanks for the prototype. This mean routing is non-trivial. I have another question. Consider url to be http://localhost/one/100 where 100 is some id in database on which selection is to be done. How can I extract 100 from the URL? Which class contains this information? I believe UHTTP will have that but in doxygen information I could not find a method which is obvious.

@victorstewart
Copy link
Collaborator

if you construct the url like this... http://localhost/one?dbID=100

then either...

  1. you can access the raw text in the UClientImage_Base::body variable
    OR
  2. you can declare "dbID" in the args section.

Here's a quick example:

benchmarking.usp

@shivshankardayal
Copy link
Author

No I do not intend to do that. That conflicts with SEO based URL design.

@stefanocasazza
Copy link
Owner

stefanocasazza commented Sep 14, 2017 via email

@victorstewart
Copy link
Collaborator

I'm not sure you can achieve what you deserve to though. You're asking for conditional url parsing, with no clear differential between cases of pure resource paths vs resource paths with an identifier tagged on.

This is the whole reason ?x=y etc exists.

If you point the request at "/one/100", that will be interpreted as a resource path.. and ULib will look for a resource at your-document-root/one/100.so

What you're asking for would require parsing that violates general URL standards / specifications.

@shivshankardayal
Copy link
Author

No it does not. For example, look at URL of a question on stackoverflow. The post id of question is embedded in URL. For example, this is achievable easily in frameworks like Django.

@stefanocasazza
Copy link
Owner

stefanocasazza commented Sep 14, 2017 via email

@shivshankardayal
Copy link
Author

Given the URL https://stackoverflow .com/questions/1657484/can-you-give-an-example-of-stack-overflow-in-c I want it to be served by questions.so and 1657484 is what needs to be extracted from URL.

@stefanocasazza
Copy link
Owner

stefanocasazza commented Sep 15, 2017 via email

@stefanocasazza
Copy link
Owner

stefanocasazza commented Sep 16, 2017

I made as general rule:
/name_of_usp/cpath1/cpath2/... be served by name_of_usp.so.
It is no more needed the config var USP_AUTOMATIC_ALIASING
I have update the prototype:
one.usp
two.usp
one.test
one.req

@shivshankardayal
Copy link
Author

Thanks a lot for helping me out Stefano. Now one more problem remains which I raised in another issue which is persistent connection to DB.

@stefanocasazza
Copy link
Owner

it is show inside one.usp

@shivshankardayal
Copy link
Author

So you mean to say that since it is static connection it will live as long as userver will keep running. I think that this issue should be closed now. Thanks a lot Stefano for all the support.

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