create-caspian-app 0.2.0-beta.85 → 0.2.0-beta.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.py +16 -5
- package/package.json +1 -1
package/dist/main.py
CHANGED
|
@@ -36,6 +36,7 @@ from casp.layout import (
|
|
|
36
36
|
import hashlib
|
|
37
37
|
from casp.streaming import SSE
|
|
38
38
|
from typing import Any, Optional, get_args, get_origin, Union
|
|
39
|
+
from urllib.parse import urlparse
|
|
39
40
|
from src.lib.auth.auth_config import build_auth_settings
|
|
40
41
|
|
|
41
42
|
load_dotenv()
|
|
@@ -61,6 +62,7 @@ app = FastAPI(
|
|
|
61
62
|
openapi_url="/openapi.json" if cfg.backendOnly else None,
|
|
62
63
|
)
|
|
63
64
|
|
|
65
|
+
|
|
64
66
|
@app.get("/health")
|
|
65
67
|
async def healthcheck():
|
|
66
68
|
return {"status": "ok"}
|
|
@@ -80,6 +82,9 @@ def _dev_cookie_scope() -> str:
|
|
|
80
82
|
return ""
|
|
81
83
|
|
|
82
84
|
scope = os.getenv("CASPIAN_BROWSER_SYNC_PORT")
|
|
85
|
+
if scope and scope.isdigit():
|
|
86
|
+
return scope
|
|
87
|
+
|
|
83
88
|
if not scope:
|
|
84
89
|
bs_config_path = Path("settings/bs-config.json")
|
|
85
90
|
if bs_config_path.exists():
|
|
@@ -87,12 +92,15 @@ def _dev_cookie_scope() -> str:
|
|
|
87
92
|
local_url = json.loads(
|
|
88
93
|
bs_config_path.read_text(encoding="utf-8")
|
|
89
94
|
).get("local", "")
|
|
90
|
-
|
|
95
|
+
parsed_url = urlparse(local_url)
|
|
96
|
+
if parsed_url.hostname in {"localhost", "127.0.0.1"}:
|
|
97
|
+
scope = str(parsed_url.port or "")
|
|
98
|
+
else:
|
|
99
|
+
scope = ""
|
|
91
100
|
except (OSError, json.JSONDecodeError):
|
|
92
101
|
scope = ""
|
|
93
102
|
|
|
94
|
-
scope
|
|
95
|
-
return scope if scope.isdigit() else ""
|
|
103
|
+
return scope if scope and scope.isdigit() else ""
|
|
96
104
|
|
|
97
105
|
|
|
98
106
|
def _scoped_cookie_name(base_name: str) -> str:
|
|
@@ -134,6 +142,7 @@ async def serve_assets(filename: str):
|
|
|
134
142
|
mime_type, _ = mimetypes.guess_type(str(file_path))
|
|
135
143
|
return FileResponse(file_path, media_type=mime_type or 'application/octet-stream')
|
|
136
144
|
|
|
145
|
+
|
|
137
146
|
@app.get('/uploads/{filename:path}')
|
|
138
147
|
async def serve_uploads(filename: str):
|
|
139
148
|
file_path = Path('public/uploads') / filename
|
|
@@ -448,7 +457,8 @@ def register_single_route(url_pattern: str, file_path: str):
|
|
|
448
457
|
if isinstance(result, tuple):
|
|
449
458
|
page_content = result[0]
|
|
450
459
|
content = str(page_content)
|
|
451
|
-
page_content_source = getattr(
|
|
460
|
+
page_content_source = getattr(
|
|
461
|
+
page_content, 'source_path', file_path)
|
|
452
462
|
if len(result) >= 2 and isinstance(result[1], dict):
|
|
453
463
|
page_layout_props = result[1]
|
|
454
464
|
else:
|
|
@@ -524,7 +534,8 @@ def register_single_route(url_pattern: str, file_path: str):
|
|
|
524
534
|
if normalized_methods:
|
|
525
535
|
route_methods = list(dict.fromkeys(normalized_methods))
|
|
526
536
|
|
|
527
|
-
app.add_api_route(url_pattern, make_handler,
|
|
537
|
+
app.add_api_route(url_pattern, make_handler,
|
|
538
|
+
methods=route_methods, name=endpoint)
|
|
528
539
|
|
|
529
540
|
|
|
530
541
|
register_routes()
|