Skip to content

Commit 8ad70e0

Browse files
committed
fix: Update static folder path and enhance backend startup script
1 parent 384b72e commit 8ad70e0

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

app/backend/hrchatbot/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
from hrchatbot.prepdocslib.filestrategy import UploadUserFileStrategy
101101
from hrchatbot.prepdocslib.listfilestrategy import File
102102

103-
bp = Blueprint("routes", __name__, static_folder="static")
103+
bp = Blueprint("routes", __name__, static_folder="../static")
104104
# Fix Windows registry issue with mimetypes
105105
mimetypes.add_type("application/javascript", ".js")
106106
mimetypes.add_type("text/css", ".css")
@@ -126,7 +126,7 @@ async def favicon():
126126
@bp.route("/assets/<path:path>")
127127
async def assets(path):
128128
return await send_from_directory(
129-
Path(__file__).resolve().parent / "static" / "assets", path
129+
Path(__file__).resolve().parent.parent / "static" / "assets", path
130130
)
131131

132132

app/backend/hrchatbot/main.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
import asyncio
12
import os
3+
import socket
24

35
from hrchatbot.app import create_app
46
from hrchatbot.load_azd_env import load_azd_env
57

6-
# WEBSITE_HOSTNAME is always set by App Service, RUNNING_IN_PRODUCTION is set in main.bicep
8+
9+
def force_bind_port(desired_port=8000):
10+
"""Force bind to port using SO_REUSEADDR"""
11+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
12+
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
13+
try:
14+
s.bind(("localhost", desired_port))
15+
return desired_port
16+
except OSError:
17+
# Still couldn't bind, find free port
18+
s.bind(("localhost", 0))
19+
return s.getsockname()[1]
20+
21+
722
RUNNING_ON_AZURE = (
823
os.getenv("WEBSITE_HOSTNAME") is not None
924
or os.getenv("RUNNING_IN_PRODUCTION") is not None
@@ -13,3 +28,8 @@
1328
load_azd_env()
1429

1530
app = create_app()
31+
32+
if __name__ == "__main__":
33+
port = force_bind_port(8000)
34+
url = f"http://localhost:{port}"
35+
asyncio.run(app.run_task(host="localhost", port=port))

app/start.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ echo ""
4444

4545
cd ../backend
4646

47-
port=50505
48-
host=localhost
49-
uv run quart --app hrchatbot.main:app run --port "$port" --host "$host" --reload
47+
uv run python -m hrchatbot.main
5048
out=$?
5149
if [ $out -ne 0 ]; then
5250
echo "Failed to start backend"

0 commit comments

Comments
 (0)