Spaces:
Running
Running
David Ko
commited on
Commit
·
c4ce70b
1
Parent(s):
e865931
fix(api): serve CRA build assets from nested static/static paths to avoid 404s
Browse files
api.py
CHANGED
@@ -1349,14 +1349,48 @@ def serve_index_html():
|
|
1349 |
@app.route('/static/<path:filename>')
|
1350 |
def static_files(filename):
|
1351 |
print(f"Serving static file: {filename}")
|
1352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1353 |
|
1354 |
# Add explicit handlers for JS files that are failing
|
1355 |
@app.route('/static/js/<path:filename>')
|
1356 |
def static_js_files(filename):
|
1357 |
print(f"Serving JS file: {filename}")
|
1358 |
-
|
1359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1360 |
|
1361 |
# 기본 경로 및 기타 경로 처리 (로그인 필요)
|
1362 |
@app.route('/', defaults={'path': ''}, methods=['GET'])
|
|
|
1349 |
@app.route('/static/<path:filename>')
|
1350 |
def static_files(filename):
|
1351 |
print(f"Serving static file: {filename}")
|
1352 |
+
# Two possible locations after CRA build copy:
|
1353 |
+
# 1) Top-level: static/<filename>
|
1354 |
+
# 2) Nested build: static/static/<filename>
|
1355 |
+
top_level_path = os.path.join(app.static_folder, filename)
|
1356 |
+
nested_dir = os.path.join(app.static_folder, 'static')
|
1357 |
+
nested_path = os.path.join(nested_dir, filename)
|
1358 |
+
|
1359 |
+
try:
|
1360 |
+
if os.path.exists(top_level_path):
|
1361 |
+
return send_from_directory(app.static_folder, filename)
|
1362 |
+
elif os.path.exists(nested_path):
|
1363 |
+
# Serve from nested build directory
|
1364 |
+
return send_from_directory(nested_dir, filename)
|
1365 |
+
else:
|
1366 |
+
# Fallback: try as-is (may help in some edge cases)
|
1367 |
+
return send_from_directory(app.static_folder, filename)
|
1368 |
+
except Exception as e:
|
1369 |
+
print(f"[DEBUG] Error serving static file '{filename}': {e}")
|
1370 |
+
# Final fallback to avoid leaking stack traces
|
1371 |
+
return ('Not Found', 404)
|
1372 |
|
1373 |
# Add explicit handlers for JS files that are failing
|
1374 |
@app.route('/static/js/<path:filename>')
|
1375 |
def static_js_files(filename):
|
1376 |
print(f"Serving JS file: {filename}")
|
1377 |
+
# Try top-level static/js and nested static/static/js
|
1378 |
+
top_js_dir = os.path.join(app.static_folder, 'js')
|
1379 |
+
nested_js_dir = os.path.join(app.static_folder, 'static', 'js')
|
1380 |
+
top_js_path = os.path.join(top_js_dir, filename)
|
1381 |
+
nested_js_path = os.path.join(nested_js_dir, filename)
|
1382 |
+
|
1383 |
+
try:
|
1384 |
+
if os.path.exists(top_js_path):
|
1385 |
+
return send_from_directory(top_js_dir, filename)
|
1386 |
+
elif os.path.exists(nested_js_path):
|
1387 |
+
return send_from_directory(nested_js_dir, filename)
|
1388 |
+
else:
|
1389 |
+
# As a fallback, let the generic static handler try
|
1390 |
+
return static_files(os.path.join('js', filename))
|
1391 |
+
except Exception as e:
|
1392 |
+
print(f"[DEBUG] Error serving JS file '{filename}': {e}")
|
1393 |
+
return ('Not Found', 404)
|
1394 |
|
1395 |
# 기본 경로 및 기타 경로 처리 (로그인 필요)
|
1396 |
@app.route('/', defaults={'path': ''}, methods=['GET'])
|