contributing: update serving locally

The self-signed certificate didn't work with the service worker, so
drop that and use a different method instead.
This commit is contained in:
David Lechner
2022-03-08 14:47:27 -06:00
parent 907826cf0e
commit d8da424472
3 changed files with 25 additions and 93 deletions
+25 -11
View File
@@ -103,20 +103,34 @@ See the section about [deployment][deployment] for more information.
[deployment]: https://facebook.github.io/create-react-app/docs/deployment
### `./tools/serve.py`
WebBluetooth requires https. So to locally test the result of `yarn build`,
run `./tools/serve.py` then point a web browser to <https://localhost:8443>
(don't leave out https!).
## Running the app locally
Usually using `yarn start` is more convenient for local development, but this is
particularly useful for testing changes on an Android device, for example. On
remote devices, replace `localhost` with the hostname or IP address of the
computer running the `./tools/serve.py` script.
For most development work, running `yarn start` will suffice (see above).
However, there are some features, like the service worker, that are disabled in
this environment. To test the site as if it was deployed in production, we can
serve up the output of `yarn build` instead.
This server uses a self-signed certificate, so the browser will complain that
the site is not secure. This warning can be ignored by clicking the *Advanced*
button and then click the link to proceed to the site.
This app uses "powerful web features" so requires a secure (https) connection.
So for local testing without https, we need to follow
<https://www.chromium.org/Home/chromium-security/deprecating-powerful-features-on-insecure-origins/#testing-powerful-features>.
To serve the website, run:
yarn build
python3 -m http.server --directory build
Note: the usual `npx serve` doesn't properly serve parts of the site so we use
Python instead.
Then at `chrome://flags/#unsafely-treat-insecure-origin-as-secure`, add:
http://localhost:8000
and restart Chromium.
The first link above also has info on how to use port forwarding to test on
Android devices.
## Learn More
-34
View File
@@ -1,34 +0,0 @@
#!/usr/bin/env python3
"""
Serve local build with https for testing.
This is useful, e.g. for Android (WebBluetooth doesn't work without https).
Usage:
yarn build
./tools/serve.py
Browse to https://localhost:8443 on the local machine or
https://<name-or-address>:8443 on a remote device.
The browser will complain about the self-signed certificate, but this can be
bypassed (click "Advanced" in browser).
"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
import os
import ssl
THIS_DIR = Path(__file__).parent
TEST_CERT = (THIS_DIR / 'test.pem').absolute()
BUILD_DIR = (THIS_DIR / '..' / 'build').absolute()
# HTTPServer serves the current directory.
os.chdir(BUILD_DIR)
httpd = HTTPServer(('', 8443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=TEST_CERT, server_side=True)
httpd.serve_forever()
-48
View File
@@ -1,48 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDLpTko58nNd2cE
q8MaB1Wv4xren/xiNomDwf44QK9jZGzvHqnXCKTQ0KsLxtZt7Ne6PU1WdIA3bf6/
nVzVUhauP0+DF8t6bTH4GSlvLXKGFW6dkCkTMw8ginh73PkZL+OaQvaMVJd42CW9
bPhFMF6tXsLq661ObXwTE+vBopSim4EEzy+VKXB8BHvMYvfMcWiJihKJhCPLZE9p
iHBO3yByMs0fLe6UQ/MAHXFVprxnXJ+P2mMe5s/c0BEcTK1deNy9ngKcUvKGCcfj
T19xtkS4IHS0csz0fkZ+93tGjTm9eCLAOmyvKRljhOMFZKV4J1w4We3Y2b+xHN9w
psukl2+JAgMBAAECggEBAKacuEZaVYYQQa3VpZs/EwEDavFnrYLhIeM1rXtymMxV
1rZQvR4ciVP61WaeOMPY+ar7CrJIQLqY+MrmwZQaREotrC0SI703Z6GXXIoEgeVn
1Yd98c0ughraj7avVPIhdzK3xKWNdBw/o6j2Za2d5Ggt1oWDath2xQOK0eEr1jWu
VNfZNMvjyvevbyzuBLlF2970ZbOKAi/nrqtmw8mlhqDK5hy+j0K37hAbxizVDmU6
vZfGhgmgBqXCla59T4rN3StK6zYVfmZKuGHWQbBxbWuLpFA+m09WKF599rUgZG7e
l5RC1dOXCa4bOv8yVRULb5LSIyBHxIfPiqShw/gUm3ECgYEA5/QkAOw4M2RSpaGb
K0yaoAKkZ5whX3rzudOVocQkeMKETpiPcLRZpO/z3A/bRjDg5YG7FNhbBI2nqGHR
ShkZIZlx7OeZPsT4IpciKDGOjoWhfk2a3gaUj+24hUO13hK1DrudI0t+USb6wj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