Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -653,33 +653,23 @@ class Demo:
|
|
653 |
def deploy_to_vercel(code: str):
|
654 |
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
655 |
try:
|
|
|
656 |
if not code or len(code.strip()) < 10:
|
657 |
-
|
658 |
-
return """
|
659 |
-
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
660 |
-
배포할 코드가 없습니다. 먼저 게임 코드를 생성해주세요.
|
661 |
-
</div>
|
662 |
-
<script>console.log('[DEBUG] 배포 실패: code가 너무 짧습니다.');</script>
|
663 |
-
"""
|
664 |
|
|
|
665 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
666 |
if not token:
|
667 |
-
|
668 |
-
return """
|
669 |
-
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
670 |
-
Vercel 토큰이 설정되지 않았습니다.
|
671 |
-
</div>
|
672 |
-
<script>console.log('[DEBUG] 배포 실패: Vercel 토큰 없음');</script>
|
673 |
-
"""
|
674 |
|
|
|
675 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
676 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
677 |
-
print(f"[DEBUG] 생성된 project_name: {project_name}")
|
678 |
-
|
679 |
headers = {
|
680 |
"Authorization": f"Bearer {token}",
|
681 |
"Content-Type": "application/json"
|
682 |
}
|
|
|
683 |
package_json = {
|
684 |
"name": project_name,
|
685 |
"version": "1.0.0",
|
@@ -691,16 +681,19 @@ def deploy_to_vercel(code: str):
|
|
691 |
"preview": "vite preview"
|
692 |
}
|
693 |
}
|
|
|
694 |
files = [
|
695 |
{"file": "index.html", "data": code},
|
696 |
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
697 |
]
|
|
|
698 |
project_settings = {
|
699 |
"buildCommand": "npm run build",
|
700 |
"outputDirectory": "dist",
|
701 |
"installCommand": "npm install",
|
702 |
"framework": None
|
703 |
}
|
|
|
704 |
deploy_data = {
|
705 |
"name": project_name,
|
706 |
"files": files,
|
@@ -711,58 +704,33 @@ def deploy_to_vercel(code: str):
|
|
711 |
print("[DEBUG] Vercel API 요청 전송중...")
|
712 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
713 |
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
714 |
-
print("[DEBUG] 응답 body:", deploy_response.text[:300], "..." if len(deploy_response.text) > 300 else "")
|
715 |
|
716 |
if deploy_response.status_code != 200:
|
717 |
-
return f""
|
718 |
-
<div style='color:red; padding:10px; border:1px solid red; border-radius:5px;'>
|
719 |
-
배포 실패: {html.escape(deploy_response.text)}
|
720 |
-
</div>
|
721 |
-
<script>console.log('[DEBUG] 배포 실패: {html.escape(deploy_response.text)}');</script>
|
722 |
-
"""
|
723 |
|
|
|
724 |
deployment_url = f"https://{project_name}.vercel.app"
|
725 |
print("[DEBUG] 배포 성공 추정. 3초 대기 후 최종 안내...")
|
726 |
time.sleep(3)
|
727 |
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
<
|
733 |
-
|
734 |
-
|
735 |
-
|
|
|
|
|
|
|
736 |
</div>
|
737 |
-
<script>
|
738 |
-
console.log('[DEBUG] 배포 성공, deployment_url: {deployment_url}');
|
739 |
-
showDeployBanner('success','✅ 배포 완료!','게임이 성공적으로 배포되었습니다.','{deployment_url}');
|
740 |
-
document.getElementById('deploy-result-box').innerHTML = `
|
741 |
-
<div class="deploy-success">
|
742 |
-
<div class="success-icon">✅</div>
|
743 |
-
<div class="success-message">배포 완료!</div>
|
744 |
-
<div class="url-box">
|
745 |
-
<a href="{deployment_url}" target="_blank">{deployment_url}</a>
|
746 |
-
<button class="copy-btn" onclick="navigator.clipboard.writeText('{deployment_url}')">복사</button>
|
747 |
-
</div>
|
748 |
-
</div>
|
749 |
-
`;
|
750 |
-
</script>
|
751 |
"""
|
752 |
-
print("[DEBUG] 최종 리턴 HTML 생성 완료")
|
753 |
-
return success_html
|
754 |
|
755 |
except Exception as e:
|
756 |
print("[ERROR] deploy_to_vercel() 예외:", e)
|
757 |
-
return f""
|
758 |
-
|
759 |
-
오류 발생: {html.escape(str(e))}
|
760 |
-
</div>
|
761 |
-
<script>
|
762 |
-
console.log('[DEBUG] deploy_to_vercel 내부 예외: {html.escape(str(e))}');
|
763 |
-
showDeployBanner('error','⚠️ 시스템 오류','{html.escape(str(e))}');
|
764 |
-
</script>
|
765 |
-
"""
|
766 |
|
767 |
|
768 |
####################################################
|
|
|
653 |
def deploy_to_vercel(code: str):
|
654 |
print("[DEBUG] deploy_to_vercel() 시작. code 길이:", len(code) if code else 0)
|
655 |
try:
|
656 |
+
# code 유효성 체크
|
657 |
if not code or len(code.strip()) < 10:
|
658 |
+
return "No code to deploy."
|
|
|
|
|
|
|
|
|
|
|
|
|
659 |
|
660 |
+
# 예시: Vercel 토큰
|
661 |
token = "A8IFZmgW2cqA4yUNlLPnci0N"
|
662 |
if not token:
|
663 |
+
return "Vercel token is not set."
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
|
665 |
+
# 프로젝트 이름
|
666 |
project_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6))
|
667 |
deploy_url = "https://api.vercel.com/v13/deployments"
|
|
|
|
|
668 |
headers = {
|
669 |
"Authorization": f"Bearer {token}",
|
670 |
"Content-Type": "application/json"
|
671 |
}
|
672 |
+
|
673 |
package_json = {
|
674 |
"name": project_name,
|
675 |
"version": "1.0.0",
|
|
|
681 |
"preview": "vite preview"
|
682 |
}
|
683 |
}
|
684 |
+
|
685 |
files = [
|
686 |
{"file": "index.html", "data": code},
|
687 |
{"file": "package.json", "data": json.dumps(package_json, indent=2)}
|
688 |
]
|
689 |
+
|
690 |
project_settings = {
|
691 |
"buildCommand": "npm run build",
|
692 |
"outputDirectory": "dist",
|
693 |
"installCommand": "npm install",
|
694 |
"framework": None
|
695 |
}
|
696 |
+
|
697 |
deploy_data = {
|
698 |
"name": project_name,
|
699 |
"files": files,
|
|
|
704 |
print("[DEBUG] Vercel API 요청 전송중...")
|
705 |
deploy_response = requests.post(deploy_url, headers=headers, json=deploy_data)
|
706 |
print("[DEBUG] 응답 status_code:", deploy_response.status_code)
|
|
|
707 |
|
708 |
if deploy_response.status_code != 200:
|
709 |
+
return f"Deployment failed: {deploy_response.text}"
|
|
|
|
|
|
|
|
|
|
|
710 |
|
711 |
+
# 정상 배포 -> URL
|
712 |
deployment_url = f"https://{project_name}.vercel.app"
|
713 |
print("[DEBUG] 배포 성공 추정. 3초 대기 후 최종 안내...")
|
714 |
time.sleep(3)
|
715 |
|
716 |
+
# ★ 여기서 스크립트 없이, 아주 단순한 HTML만 반환 ★
|
717 |
+
# ex) "Deployment complete! <a href='...' target='_blank'> ...</a>"
|
718 |
+
return f"""
|
719 |
+
<div style="border:1px solid #4CAF50; padding:12px; border-radius:8px;">
|
720 |
+
<h3 style="color:#4CAF50;">Deployment complete!</h3>
|
721 |
+
<p style="margin:0;">
|
722 |
+
Visit your deployed page:
|
723 |
+
<a href="{deployment_url}" target="_blank" style="color:#1890ff; text-decoration:underline;">
|
724 |
+
{deployment_url}
|
725 |
+
</a>
|
726 |
+
</p>
|
727 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
728 |
"""
|
|
|
|
|
729 |
|
730 |
except Exception as e:
|
731 |
print("[ERROR] deploy_to_vercel() 예외:", e)
|
732 |
+
return f"Error during deployment: {str(e)}"
|
733 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
734 |
|
735 |
|
736 |
####################################################
|