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 set upstream to same server #124

Open
JoePercipientAI opened this issue Apr 2, 2021 · 2 comments
Open

How to set upstream to same server #124

JoePercipientAI opened this issue Apr 2, 2021 · 2 comments

Comments

@JoePercipientAI
Copy link

I want to set up a reverse proxy that will redirect a Django app URL to another part of the same website that is outside of Django.

(for example):

www.mysite.com/MyDjangoApp/foo/ -> www.mysite.com/bar/

And of course, I need this to work for whatever domain/server the app is installed on.

The example in the docs only shows redirecting to a static alternate domain (upstream='http://example.com/'). What to I set "upstream" to in order to use whatever server the original request was made to, instead of always going to example.com?

@otuoma
Copy link

otuoma commented Apr 4, 2021

I have not tested this, but if you create a view that extends ProxyView like this, it should allow you to set the upstream URL to whatever is passed in the url GET parameter.

from revproxy.views import ProxyView
from django.http import HttpResponse

class MyProxyView(ProxyView):

    def get(self, request):
        self.upstream = request.GET.get('upstream') 
        return HttpResponse(revproxy.response)

@JoePercipientAI
Copy link
Author

@otuoma Thanks. I have tried setting "upstream" from code, and it works if I set it to just a host, like http://www.mysite.com/, but if I add anything else at the end of the URL, like in my example www.mysite.com/bar/, then I get an exception:

AttributeError: 'MyProxyView' object has no attribute '_parsed_url'

For my use case, I definitely need to have the additional part to the path.

Is django-revproxy not going to work for me?

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