-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
26 lines (21 loc) · 763 Bytes
/
server.py
File metadata and controls
26 lines (21 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from starlette.applications import Starlette
from starlette.routing import Mount
from starlette.staticfiles import StaticFiles
import uvicorn
import os
import sys
# Configuration
serve_dir = os.environ.get("SERVE_DIR", "dist")
# Ensure directory exists
if not os.path.exists(serve_dir):
print(f"Error: '{serve_dir}' directory not found. Do you need to run 'just build'?")
sys.exit(1)
routes = [
Mount('/', app=StaticFiles(directory=serve_dir, html=True), name='static'),
]
app = Starlette(debug=True, routes=routes)
if __name__ == "__main__":
host = os.environ.get("HOST", "0.0.0.0")
port = int(os.environ.get("PORT", 8000))
print(f"Serving directory '{serve_dir}' at http://{host}:{port}")
uvicorn.run(app, host=host, port=port)