Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondChuiHW committed Mar 5, 2024
1 parent 1ee6af5 commit cb7ce4f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ This repository is a fork of [ChromeDevTools/devtools-frontend](https://github.c
### Build and run

```sh
# Build continuously with a file watcher
npm run watch
# Build with the default config once
npm run build
# or npm run build-release
# Build with the release config once
npm run build-release
```

This can then be served from a static web server to test locally:

```sh
./serve-dev.py 8000
./serve-local.py 8000
```

The frontend will be available at `http://localhost:8000/debugger-frontend/inspector.html` (or `http://localhost:8000/debugger-frontend/rn_inspector.html` for the RN-specific entry point).
The React Native frontend will be available at `http://localhost:8000/debugger-frontend/rn_inspector.html`.

## Contributing

Expand Down
25 changes: 23 additions & 2 deletions serve-dev.py → serve-local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import sys
from http import HTTPStatus
from http.server import HTTPServer, SimpleHTTPRequestHandler
from os import path
from urllib.parse import urljoin

parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(
epilog="Serves the dev output directory on the specified port."
)

parser.add_argument("port", type=int, help="Port number, e.g. 8000")
parser.add_argument(
Expand All @@ -26,11 +29,19 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, directory="out/Default/gen/front_end", **kwargs)

def translate_path(self, path):
"""
We treat `/debugger-frontend` URL path as the root path of the file system.
This reflects the URL path of Chrome DevTools when served from Metro.
"""
if path.startswith("/debugger-frontend/"):
path = path.split("/debugger-frontend")[1]
return super().translate_path(path)

def redirect_to_debugger_frontend(self):
"""
When launched from Metro, Chrome DevTools is served at `/debugger-frontend`.
This redirect allows relative URL paths to resolve as if it's served from Metro.
"""
self.send_response(HTTPStatus.PERMANENT_REDIRECT)
relative_path = self.path[1:]
self.send_header("Location", urljoin("/debugger-frontend/", relative_path))
Expand All @@ -43,19 +54,29 @@ def do_GET(self):
if REDIRECT_BASE_URL is None:
return super().do_GET()

self.redirect_static_path()

def redirect_static_path():
if not self.path.startswith("/debugger-frontend/static/"):
return super().do_GET()

print("Redirecting")
self.send_response(HTTPStatus.TEMPORARY_REDIRECT)
self.send_header("Location", urljoin(REDIRECT_BASE_URL, self.path))
self.end_headers()


server_address = (
"", # server_name
"", # Empty server_name for localhost
PORT,
)

with HTTPServer(server_address, Handler) as httpd:
output_dir = path.abspath("./out/Default/gen/front_end")
print(f"Serving at http://localhost:{PORT}/debugger-frontend/rn_inspector.html")
print(f"Serving files from {output_dir}")
if REDIRECT_BASE_URL is not None:
print(
f"Redirecting /debugger-frontend/static/* requests to {REDIRECT_BASE_URL}"
)
httpd.serve_forever()

0 comments on commit cb7ce4f

Please sign in to comment.