Skip to content

Commit 5fb4811

Browse files
committed
Added example of using HTTPS
1 parent 9b06f5a commit 5fb4811

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/httpserver_https.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2024 Michał Pokusa
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import socketpool
6+
import wifi
7+
8+
from adafruit_httpserver import Server, Request, Response
9+
10+
11+
pool = socketpool.SocketPool(wifi.radio)
12+
server = Server(
13+
pool,
14+
root_path="/static",
15+
https=True,
16+
certfile="cert.pem",
17+
keyfile="key.pem",
18+
debug=True,
19+
)
20+
21+
22+
@server.route("/")
23+
def base(request: Request):
24+
"""
25+
Serve a default static plain text message.
26+
"""
27+
return Response(request, "Hello from the CircuitPython HTTPS Server!")
28+
29+
30+
server.serve_forever(str(wifi.radio.ipv4_address), 443)

0 commit comments

Comments
 (0)