Clarify support for virtual hosting
This commit is contained in:
parent
9ac80a986c
commit
961d42e3e2
16
README.md
16
README.md
|
@ -130,6 +130,22 @@ a directory is requested, jetforce will look for a file named **index.gmi** in t
|
||||||
directory to return. Otherwise, a directory file listing will be automatically
|
directory to return. Otherwise, a directory file listing will be automatically
|
||||||
generated.
|
generated.
|
||||||
|
|
||||||
|
### Virtual Hosting
|
||||||
|
|
||||||
|
For the sake of keeping the command line arguments straightforward and easy
|
||||||
|
to understand, configuring virtual hosting is not supported via the command
|
||||||
|
line. However, it is readily available using only a few lines of python and a
|
||||||
|
custom launch script. Check out [examples/vhost.py](examples/vhost.py) for more
|
||||||
|
information.
|
||||||
|
|
||||||
|
Jetforce does not (yet) support virtual hosting at the TLS-layer using SNI.
|
||||||
|
This means that you cannot return different server TLS certificates for
|
||||||
|
different domains. The suggested workaround is to use a single certificate with
|
||||||
|
multiple ``subjectAltName`` attributes. There is also an
|
||||||
|
[sni_callback()](https://github.com/michael-lazar/jetforce/blob/9ac80a986c6ed8a62951c857315ca04b6d127c32/jetforce/tls.py#L140)
|
||||||
|
hook in the server codebase that can be subclassed to implement custom TLS
|
||||||
|
behavior.
|
||||||
|
|
||||||
### CGI
|
### CGI
|
||||||
|
|
||||||
Jetforce supports a simplified version of CGI scripting. It doesn't
|
Jetforce supports a simplified version of CGI scripting. It doesn't
|
||||||
|
|
|
@ -1,36 +1,41 @@
|
||||||
"""
|
"""
|
||||||
A server that implements virtual hosting for multiple subdomains.
|
A server that implements virtual hosting for subdomains.
|
||||||
|
|
||||||
This is a basic example of you how can run multiple apps from the same server
|
This is a basic example of you how can run multiple apps from the same server.
|
||||||
by creating a composite application.
|
You can use different static directories for different domains, or even combine
|
||||||
|
static applications with your own custom JetforceApplication classes.
|
||||||
|
|
||||||
> jetforce-client gemini://apple.localhost --host localhost
|
> jetforce-client gemini://app-a.example.com --host localhost
|
||||||
> jetforce-client gemini://banana.localhost --host localhost
|
> jetforce-client gemini://app-b.example.com --host localhost
|
||||||
|
|
||||||
|
This is how gemini://astrobotany.mozz.us is served alongside gemini://mozz.us:
|
||||||
|
|
||||||
|
```
|
||||||
|
app = jetforce.CompositeApplication(
|
||||||
|
{
|
||||||
|
"astrobotany.mozz.us": astrobotany_application,
|
||||||
|
None: StaticDirectoryApplication(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
from jetforce import GeminiServer, StaticDirectoryApplication
|
||||||
from jetforce.app.composite import CompositeApplication
|
from jetforce.app.composite import CompositeApplication
|
||||||
|
|
||||||
apple = JetforceApplication()
|
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(
|
||||||
@apple.route()
|
{
|
||||||
def index(request):
|
"app-a.example.com": app_a,
|
||||||
return Response(Status.SUCCESS, "text/plain", "apple!")
|
"app-b.example.com": app_b,
|
||||||
|
# Use a default static file server for all other domains
|
||||||
|
None: app_default,
|
||||||
banana = JetforceApplication()
|
}
|
||||||
|
|
||||||
|
|
||||||
@banana.route()
|
|
||||||
def index(request):
|
|
||||||
return Response(Status.SUCCESS, "text/plain", "banana!")
|
|
||||||
|
|
||||||
|
|
||||||
composite_app = CompositeApplication(
|
|
||||||
{"apple.localhost": apple, "banana.localhost": banana}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
server = GeminiServer(composite_app)
|
server = GeminiServer(app)
|
||||||
server.run()
|
server.run()
|
||||||
|
|
Loading…
Reference in New Issue