Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions scripts/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import http.server
import pathlib
import socketserver
import ssl

BUILD_DIR = (pathlib.Path(__file__).parent.parent / "build").resolve()
CERT_FILE = BUILD_DIR / "cert.pem"
KEY_FILE = BUILD_DIR / "key.pem"
PORT = 8000


Expand All @@ -17,10 +19,10 @@ def __init__(
self,
request: bytes,
client_address: tuple[str, int],
server: socketserver.BaseServer,
server: http.server.HTTPServer,
directory: str | None = ...
) -> None:
super().__init__(request, client_address, server, directory=BUILD_DIR)
super().__init__(request, client_address, server, directory=str(BUILD_DIR))

def end_headers(self) -> None:
# custom headers needed for some web API features
Expand All @@ -29,6 +31,14 @@ def end_headers(self) -> None:
return super().end_headers()


with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"serving at http://0.0.0.0:{PORT}")
httpd.serve_forever()
httpd = http.server.HTTPServer(("", PORT), Handler)

if CERT_FILE.exists() and KEY_FILE.exists():
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain(certfile=CERT_FILE, keyfile=KEY_FILE)
httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
print(f"serving at https://0.0.0.0:{PORT}")
else:
print(f"cert/key not found, serving without TLS at http://0.0.0.0:{PORT}")

httpd.serve_forever()
4 changes: 0 additions & 4 deletions src/usb/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
continue;
}

console.debug('Received USB message:', result.data);

switch (result.data.getInt8(0)) {
case PybricksUsbInEndpointMessageType.Response:
yield* put(
Expand Down Expand Up @@ -509,8 +507,6 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
for (;;) {
const action = yield* take(chan);

console.debug('Processing USB action:', action);

if (usbPybricksSubscribe.matches(action)) {
const message = new DataView(new ArrayBuffer(2));
message.setUint8(0, PybricksUsbOutEndpointMessageType.Subscribe);
Expand Down
Loading