Serving two different ports within a single script
eloi.le-bastart-de-villeneuve-wfpxC6D80PtWj0EZb7rXcA@public.gmane.org
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I've been using Cherrypy for a few days, and despite an intense tracking
through the scarce and elliptic doc, I didn't manage to serve two different
apps on two different ports of my server.
My strategy is to provide a simple hello world script to the port 443 and a
redirect when you call port 80. Here is the code :
import cherrypy
class HelloWorld:
@cherrypy.expose
def index(self):
return "Hello World!"
class Redirect:
@cherrypy.expose
def index(self):
raise cherrypy.HTTPRedirect("https://whatever.url.com")
root = HelloWorld()
RootApp = cherrypy.Application(root)
hello_world = cherrypy.Application(root)
redirect = cherrypy.Application(Redirect())
vh = cherrypy._cpwsgi.VirtualHost(root,
domains={
'0.0.0.0:443' : hello_world,
'0.0.0.0:80' : redirect
}
)
cherrypy.tree.mount(root, "/", conf)
cherrypy.tree.graft(vh)
cherrypy.config.update({
'log.access_file': "access1.log",
'log.screen' : True,
'tools.sessions.on': True,
'server.socket_host' : '0.0.0.0',
'server.socket_port' : 80,
'server.ssl_module' : 'builtin'
})
cherrypy.engine.start()
cherrypy.engine.block()
Right now this doesn't even work anymore ; I'm getting a
'HelloWorld' object is not callable
answer.
But if I happen to remove this part :
root = HelloWorld()
RootApp = cherrypy.Application(root)
hello_world = cherrypy.Application(root)
redirect = cherrypy.Application(Redirect())
vh = cherrypy._cpwsgi.VirtualHost(root,
domains={
'0.0.0.0:443' : hello_world,
'0.0.0.0:80' : redirect
}
)
cherrypy.tree.mount(root, "/", conf)
cherrypy.tree.graft(vh)
which causes the previous issue, visiting http://localhost/ just (almost)
randomly redirects to https://whatever.url.com/
How do i get
- http://localhost:443 to execute HelloWorld
- http://localhost:80 to redirect
in the same script?
Thank you in advance
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.