/examples/web/virtualhosts.py

https://bitbucket.org/prologic/circuits/ · Python · 38 lines · 23 code · 14 blank · 1 comment · 0 complexity · c53fcdafc2b67d617aac56f853f53427 MD5 · raw file

  1. #!/usr/bin/env python
  2. from circuits.web import Server, Controller
  3. from circuits.web.dispatchers import VirtualHosts
  4. class Root(Controller):
  5. def index(self):
  6. return "I am the main vhost"
  7. class Foo(Controller):
  8. channel = "/foo"
  9. def index(self):
  10. return "I am foo."
  11. class Bar(Controller):
  12. channel = "/bar"
  13. def index(self):
  14. return "I am bar."
  15. domains = {
  16. "foo.localdomain:8000": "foo",
  17. "bar.localdomain:8000": "bar",
  18. }
  19. app = Server(("0.0.0.0", 8000))
  20. VirtualHosts(domains).register(app)
  21. Root().register(app)
  22. Foo().register(app)
  23. Bar().register(app)
  24. app.run()