| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
import cherrypy |
|---|
| 4 |
from cherrypy import expose |
|---|
| 5 |
|
|---|
| 6 |
class Root(object): |
|---|
| 7 |
|
|---|
| 8 |
@expose |
|---|
| 9 |
def index(self): |
|---|
| 10 |
return "I am the main vhost" |
|---|
| 11 |
|
|---|
| 12 |
class Foo(object): |
|---|
| 13 |
|
|---|
| 14 |
@expose |
|---|
| 15 |
def index(self): |
|---|
| 16 |
return "I am foo." |
|---|
| 17 |
|
|---|
| 18 |
class Bar(object): |
|---|
| 19 |
|
|---|
| 20 |
@expose |
|---|
| 21 |
def index(self): |
|---|
| 22 |
return "I am bar." |
|---|
| 23 |
|
|---|
| 24 |
def main(): |
|---|
| 25 |
cherrypy.config.update("conf.ini") |
|---|
| 26 |
|
|---|
| 27 |
conf = { |
|---|
| 28 |
"/": { |
|---|
| 29 |
"request.dispatch": cherrypy.dispatch.VirtualHost( |
|---|
| 30 |
**{ |
|---|
| 31 |
"foo.domain.com:8000": "/foo", |
|---|
| 32 |
"bar.domain.com:8000": "/bar" |
|---|
| 33 |
} |
|---|
| 34 |
) |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
root = Root() |
|---|
| 39 |
root.foo = Foo() |
|---|
| 40 |
root.bar = Bar() |
|---|
| 41 |
cherrypy.tree.mount(root, "/", conf) |
|---|
| 42 |
|
|---|
| 43 |
cherrypy.server.quickstart() |
|---|
| 44 |
cherrypy.engine.start() |
|---|
| 45 |
|
|---|
| 46 |
if __name__ == "__main__": |
|---|
| 47 |
main() |
|---|