I am trying to use the Twisted.Web framework.
Note the three line comments (# line1, # line2, # line3). I want to create a proxy (gateway?) That will redirect the request to one of the two servers depending on the URL. If I uncomment the comment 1 or 2 (and comment the rest), the request is proxied to the correct server. However, of course, he does not select a server based on the URL.
from twisted.internet import reactor
from twisted.web import proxy, server
from twisted.web.resource import Resource
class Simple(Resource):
isLeaf = True
allowedMethods = ("GET","POST")
def getChild(self, name, request):
if name == "/" or name == "":
return proxy.ReverseProxyResource('localhost', 8086, '')
else:
return proxy.ReverseProxyResource('localhost', 8085, '')
simple = Simple()
site = server.Site(simple)
reactor.listenTCP(8080, site)
reactor.run()
Since the above code is currently standing when I run this script and go to the server "localhost: 8080 / ANYTHING_AT_ALL", I get the following response.
Method not allowed
Your browser approached me (at / ANYTHING_AT_ALL) using the "GET" method. I only allow GET, POST methods.
, ? .