Update other examples
This commit is contained in:
parent
43907a0e44
commit
b7c3e43ac4
|
@ -15,7 +15,6 @@ requests. Try requesting this endpoint over two connections simultaneously.
|
||||||
> jetforce-client gemini://localhost
|
> jetforce-client gemini://localhost
|
||||||
> jetforce-client gemini://localhost
|
> jetforce-client gemini://localhost
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
A simple guestbook application that accepts and displays text messages.
|
A simple guestbook application that accepts and displays text messages.
|
||||||
|
|
||||||
This is an example of how to return a 10 INPUT request to the client and
|
This is an example of how to return a 10 INPUT request to the client and
|
||||||
retrieve their response by parsing the URL query string. This example stores
|
retrieve their response by parsing the URL query string.
|
||||||
the guestbook inside of a persistent sqlite database.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
This example stores the guestbook inside of a persistent sqlite database.
|
||||||
|
Because each request will run inside of a separate thread, we must create a new
|
||||||
|
connection object inside of the request handler instead of re-using a global
|
||||||
|
database connection. This thread-safety can be disabled in sqlite3 by using the
|
||||||
|
check_same_thread=False argument, but then it's up to you to ensure that only
|
||||||
|
connection request is writing to the database at any given time.
|
||||||
|
"""
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
"""
|
"""
|
||||||
This is an example of setting up a Gemini server to proxy requests to other
|
A server that proxies HTTP websites over gemini.
|
||||||
protocols. This application will accept HTTP URLs, download and render them
|
|
||||||
locally using the `w3m` tool, and render the output to the client as plain text.
|
This example demonstrates how your application routes aren't just limited to
|
||||||
|
gemini URLs. The server will accept any HTTP URL, download the page and
|
||||||
|
render it using the external `w3m` tool, and then render the output to the
|
||||||
|
client as plain-text.
|
||||||
|
|
||||||
|
Most gemini clients won't be able to make this request, because the hostname
|
||||||
|
in the URL doesn't match the hostname of the server. You can test this out
|
||||||
|
using jetforce-client like this:
|
||||||
|
|
||||||
|
> jetforce-client https://mozz.us --host localhost
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import jetforce
|
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
||||||
from jetforce import Response, Status
|
|
||||||
|
|
||||||
app = jetforce.JetforceApplication()
|
app = JetforceApplication()
|
||||||
|
|
||||||
|
|
||||||
@app.route(scheme="https", strict_hostname=False)
|
@app.route(scheme="https", strict_hostname=False)
|
||||||
|
@ -26,15 +33,5 @@ def proxy_request(request):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = jetforce.command_line_parser().parse_args()
|
server = GeminiServer(app)
|
||||||
ssl_context = jetforce.make_ssl_context(
|
server.run()
|
||||||
args.hostname, args.certfile, args.keyfile, args.cafile, args.capath
|
|
||||||
)
|
|
||||||
server = jetforce.GeminiServer(
|
|
||||||
host=args.host,
|
|
||||||
port=args.port,
|
|
||||||
ssl_context=ssl_context,
|
|
||||||
hostname=args.hostname,
|
|
||||||
app=app,
|
|
||||||
)
|
|
||||||
asyncio.run(server.run())
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ isort:skip_file
|
||||||
"""
|
"""
|
||||||
from .__version__ import __version__
|
from .__version__ import __version__
|
||||||
from .app.base import JetforceApplication, Request, Response, RoutePattern, Status
|
from .app.base import JetforceApplication, Request, Response, RoutePattern, Status
|
||||||
|
from .app.static import StaticDirectoryApplication
|
||||||
|
from .app.composite import CompositeApplication
|
||||||
from .protocol import GeminiProtocol
|
from .protocol import GeminiProtocol
|
||||||
from .server import GeminiServer
|
from .server import GeminiServer
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue