From 1b9371a943e3aa6d59003eca50517b08fe0d2725 Mon Sep 17 00:00:00 2001 From: michalpokusa <72110769+michalpokusa@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:25:06 +0000 Subject: [PATCH] Added example of using HTTPS --- examples/httpserver_https.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/httpserver_https.py diff --git a/examples/httpserver_https.py b/examples/httpserver_https.py new file mode 100644 index 0000000..c006676 --- /dev/null +++ b/examples/httpserver_https.py @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: 2024 MichaƂ Pokusa +# +# SPDX-License-Identifier: Unlicense + +import socketpool +import wifi + +from adafruit_httpserver import Server, Request, Response + + +pool = socketpool.SocketPool(wifi.radio) +server = Server( + pool, + root_path="/static", + https=True, + certfile="cert.pem", + keyfile="key.pem", + debug=True, +) + + +@server.route("/") +def base(request: Request): + """ + Serve a default static plain text message. + """ + return Response(request, "Hello from the CircuitPython HTTPS Server!") + + +server.serve_forever(str(wifi.radio.ipv4_address), 443)