2

app, built with Flask. I want to have the following routing :

"/"     -> my Flask app
"/foo/" -> Reverse proxy toward http://bar/

So far, I don't have any reverse proxy, so my application looks like :

import app
[...]
if __name__ == '__main__':
    app.app.secret_key = 'XXX'
    app.app.run(debug=True, use_reloader=False)

I would like to have the whole project only in python. I don't want any Apache or nginx stack (the project is not meant to be on public network). I saw that I could use a Python WSGI server, such as "wsgiserver" in cherrypy, so my app would be:

from cherrypy import wsgiserver
import app

d = wsgiserver.WSGIPathInfoDispatcher({
    '/': app.app.wsgi_app
})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), d)

if __name__ == '__main__':
      server.start()

And if I want to add a reverse proxy in "/foo", I guess I'll just need to :

from cherrypy import wsgiserver
import app

d = wsgiserver.WSGIPathInfoDispatcher({
    '/': app.app.wsgi_app,
    '/foo/': SOME_WSGI_REVERSE_PROXY
})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), d)

if __name__ == '__main__':
      server.start()

So my questions are :

  • Is there any reverse proxy, written in python, that are WSGI compliant ? (I don't know if any SOME_WSGI_REVERSE_PROXY exists)
  • Would it work with this kind of implementation ?
user4157124
  • 2,809
  • 13
  • 27
  • 42
Blusky
  • 3,470
  • 1
  • 19
  • 35
  • 1
    Please don't edit questions to include answers in them. That's what the answer section is for. You can post an answer yourself. – Artjom B. Aug 06 '15 at 20:11

2 Answers2

0

This seems to be an actively maintained alternative to the original wsgiproxy now: https://pypi.org/project/WSGIProxy2/

Glyph
  • 31,152
  • 11
  • 87
  • 129
-1

mitmproxy: mitmproxy.org It's a python proxy with reverse proxy capability.

Leo Pepe
  • 319
  • 2
  • 5