jetforce/examples/vhost.py

42 lines
1.3 KiB
Python
Raw Normal View History

2020-05-19 05:52:05 +02:00
"""
2020-06-04 19:36:57 +02:00
A server that implements virtual hosting for subdomains.
2020-05-19 05:52:05 +02:00
2020-06-04 19:36:57 +02:00
This is a basic example of you how can run multiple apps from the same server.
You can use different static directories for different domains, or even combine
static applications with your own custom JetforceApplication classes.
2020-05-19 05:52:05 +02:00
2020-06-04 19:36:57 +02:00
> jetforce-client gemini://app-a.example.com --host localhost
> jetforce-client gemini://app-b.example.com --host localhost
2020-05-19 05:52:05 +02:00
2020-06-04 19:36:57 +02:00
This is how gemini://astrobotany.mozz.us is served alongside gemini://mozz.us:
2020-05-19 05:52:05 +02:00
2020-06-04 19:36:57 +02:00
```
app = jetforce.CompositeApplication(
{
"astrobotany.mozz.us": astrobotany_application,
None: StaticDirectoryApplication(),
}
)
```
"""
from jetforce import GeminiServer, StaticDirectoryApplication
from jetforce.app.composite import CompositeApplication
2020-05-19 05:52:05 +02:00
2020-06-04 19:36:57 +02:00
app_a = StaticDirectoryApplication(root_directory="/var/custom_directory_a/")
app_b = StaticDirectoryApplication(root_directory="/var/custom_directory_b/")
app_default = StaticDirectoryApplication(root_directory="/var/gemini/")
app = CompositeApplication(
{
"app-a.example.com": app_a,
"app-b.example.com": app_b,
# Use a default static file server for all other domains
None: app_default,
}
2020-05-19 05:52:05 +02:00
)
if __name__ == "__main__":
2020-06-04 19:36:57 +02:00
server = GeminiServer(app)
2020-05-19 05:52:05 +02:00
server.run()