openfree commited on
Commit
16de7a8
·
verified ·
1 Parent(s): d6e6623

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -732,23 +732,33 @@ def handle_deploy_legacy(code):
732
  logger.info("[handle_deploy_legacy] 코드가 짧음.")
733
  return "<div style='color:red;'>배포할 코드가 없습니다.</div>"
734
 
 
735
  clean_code = remove_code_block(code)
736
- logger.debug(f"[handle_deploy_legacy] remove_code_block 후 길이: {len(clean_code)}")
737
 
738
- result_html = deploy_to_vercel(clean_code)
739
- logger.debug(f"[handle_deploy_legacy] 배포 결과 HTML 길이: {len(result_html)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
740
 
741
- encoded_html = base64.b64encode(result_html.encode('utf-8')).decode()
742
- data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
743
 
744
- iframe_html = f"""
745
- <iframe src="{data_uri}"
746
- style="width:100%; height:600px; border:none;"
747
- sandbox="allow-scripts allow-same-origin allow-popups">
748
- </iframe>
749
- """
750
- logger.debug("[handle_deploy_legacy] iframe_html 반환")
751
- return iframe_html
752
 
753
 
754
  # ------------------------
 
732
  logger.info("[handle_deploy_legacy] 코드가 짧음.")
733
  return "<div style='color:red;'>배포할 코드가 없습니다.</div>"
734
 
735
+ # 1) 코드 블록 제거
736
  clean_code = remove_code_block(code)
 
737
 
738
+ # 2) Vercel에 배포
739
+ result = deploy_to_vercel(clean_code)
740
+ logger.debug(f"[handle_deploy_legacy] deploy_to_vercel 결과: {result}")
741
+
742
+ # 3) 배포 URL 추출
743
+ import re
744
+ match = re.search(r'https?://[\\w\\-]+\\.vercel\\.app', result)
745
+ if match:
746
+ deployment_url = match.group(0)
747
+ # 4) iframe으로 직접 렌더링
748
+ iframe_html = (
749
+ f'<iframe src="{deployment_url}" '
750
+ 'width="100%" height="600px" style="border:none;" '
751
+ 'sandbox="allow-scripts allow-same-origin allow-popups"></iframe>'
752
+ )
753
+ logger.debug("[handle_deploy_legacy] iframe_html 반환")
754
+ return iframe_html
755
+
756
+ # 5) URL 못 찾으면 오류 메시지
757
+ logger.warning("[handle_deploy_legacy] 배포 URL을 찾을 수 없음")
758
+ safe_result = html.escape(result)
759
+ return f"<div style='color:red;'>배포 URL을 찾을 수 없습니다.<br>결과: {safe_result}</div>"
760
 
 
 
761
 
 
 
 
 
 
 
 
 
762
 
763
 
764
  # ------------------------