Skip to content

Commit 759c53d

Browse files
committed
script to start http server
1 parent 8c48e05 commit 759c53d

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

web-report/index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@
77
<title>WFC Reports</title>
88
</head>
99
<body>
10-
<div id="root"></div>
10+
<div id="root">
11+
<h2>WARNING</h2>
12+
<p>
13+
If you see this message, it means the web app was not properly started.
14+
For example, if you opened the index.html file directly, that would be loaded with file:// protocol
15+
in your browser.
16+
By default, modern browsers block loading local files due to CORS issues.
17+
You need to open the web app via an HTTP server.
18+
</p>
19+
20+
<p>
21+
To simplify the visualization of the web report, we provide a webreport.py script to start a HTTP server,
22+
and automatically open your browser on the starting page of the report.
23+
To simplify its use, we also provide a webreport.command (for Mac) and webreport.bat (for Windows) to easily start the
24+
Python script with a simple mouse double-click.
25+
</p>
26+
27+
</div>
1128
<script type="module" src="/src/main.tsx"></script>
1229
</body>
1330
</html>

web-report/webreport.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
setlocal
3+
4+
:: Get the directory where this batch file is located
5+
set "SCRIPT_DIR=%~dp0"
6+
7+
:: Navigate to the script directory
8+
cd /d "%SCRIPT_DIR%"
9+
10+
:: Check if Python is installed
11+
where python >nul 2>&1
12+
if %ERRORLEVEL% neq 0 (
13+
echo Error: Python not found in PATH.
14+
echo Install Python from https://www.python.org/downloads/
15+
pause
16+
exit /b 1
17+
)
18+
19+
python "webreport.py"
20+
21+
pause

web-report/webreport.command

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/zsh
2+
cd "$(dirname "$0")" # Navigates to the script's folder
3+
python3 webreport.py || {
4+
echo "Error: Failed to run the Python script."
5+
echo "Possible fixes:"
6+
echo "1. Ensure 'python3' is installed (run 'python3 --version')."
7+
echo "2. Check if 'webreport.py' exists in the same folder."
8+
}
9+
read -r "?Press Enter to close..."

web-report/webreport.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import http.server
2+
import socketserver
3+
import webbrowser
4+
import os
5+
from threading import Timer
6+
7+
PORT = 8000
8+
HOST = "localhost"
9+
10+
class Handler(http.server.SimpleHTTPRequestHandler):
11+
def __init__(self, *args, **kwargs):
12+
super().__init__(*args, directory=os.getcwd(), **kwargs)
13+
14+
def start_server():
15+
with socketserver.TCPServer((HOST, PORT), Handler) as httpd:
16+
print(f"Serving at http://{HOST}:{PORT}")
17+
webbrowser.open_new_tab(f"http://{HOST}:{PORT}")
18+
httpd.serve_forever()
19+
20+
if __name__ == "__main__":
21+
start_server()

0 commit comments

Comments
 (0)