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

Need to handle base URL #39

Closed
Timokasse opened this issue May 3, 2015 · 2 comments
Closed

Need to handle base URL #39

Timokasse opened this issue May 3, 2015 · 2 comments

Comments

@Timokasse
Copy link

Hello,

Let's say you want to have http://myproxy/toto.html redirect to http://proxied/toto.html. Then a simple url(r'^(?P<path>.*)$', ProxyView.as_view(upstream='http://proxied/')) will do the trick. And the static files in the page will also work properly. It will, for example refer to http://myproxy/css/default.css properly.

Now you may want to have a base URL because this proxy will work for more than one site, for example. You would want something like this:

url(r'^app1/(?P<path>.*)$', ProxyView.as_view(upstream='http://hostapp1/')),
url(r'^app2/(?P<path>.*)$', ProxyView.as_view(upstream='http://hostapp2/')),

But it doesn't work because all static files will forget about the base url app1 or app2. So the page http://myproxy/app1/toto.html will refer to http://myproxy/css/default.css instead of http://myproxy/app1/css/default.css.

Please add the possibility to handle this in revproxy.

Thanks,
Timok

@seocam
Copy link
Contributor

seocam commented May 18, 2015

@Timokasse we, as all reverse proxies I know don't actually change the the path of other secondary requests. In fact each request is a new request. So, if you request in your browser the page http://myproxy/app1/toto.html your page can refer the css in many different ways. Usually ways are:

  • css/default.css: in this case your page would probably serve the css correctly because the path is relative. In the other hand it's usually somehow confusing to handle relative links from your page.
  • /css/default.css: in this case it will not work because the path is hard coded (starting with a slash). In this case you would get the result you commented above.
  • http://myproxy/css/default.css: here is the same case than above but a bit worse because hard coding the hostname is not such a good idea (if you change the domain you would have to look for it and replace in all the code).
    /css/default.css
  • /<PREFIX>/css/default.css: and last but not least, you can prefix your imports with a configurable variable. That's how usually big apps handle proxing nicely. If you are using a web framework they usually provide you a way of doing this prefix. If you are not you could take a look at saas or less for instance.

So, basically you app has to be minimally prepared to work with proxies.

@seocam seocam closed this as completed Jun 6, 2015
@seocam
Copy link
Contributor

seocam commented Jun 6, 2015

@Timokasse if you have any doubts please or disagree with my answer please reopen.

Cheers

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

2 participants