File size: 1,659 Bytes
1b7ef07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

import os
import subprocess
import sys
import time
import threading

def install_dependencies():
    print("πŸš€ Installing dependencies...")
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
    subprocess.check_call([sys.executable, "-m", "pip", "install", "pyngrok", "nest_asyncio", "uvicorn"])

def run_server():
    print("πŸ”₯ Starting FastAPI Server...")
    # Run server.py using python command to ensure it runs as a script
    subprocess.run([sys.executable, "server.py"], check=True)

def start_ngrok():
    from pyngrok import ngrok
    
    token = input("πŸ”‘ Enter your Ngrok Authtoken (from https://dashboard.ngrok.com/get-started/your-authtoken): ")
    if not token:
        print("❌ Error: Ngrok token is required.")
        return

    ngrok.set_auth_token(token)
    
    # Start tunnel to port 8000
    public_url = ngrok.connect(8000).public_url
    print(f"\nβœ… \033[92mPublic Backend URL: {public_url}\033[0m")
    print("πŸ‘‰ Copy this URL and paste it into the 'Backend Connection' box on your Vercel website.\n")
    
    # Keep functionality alive
    try:
        # Run server in main thread or subprocess
        run_server()
    except KeyboardInterrupt:
        print("Stopping...")
        ngrok.kill()

if __name__ == "__main__":
    if not os.path.exists("server.py"):
        print("❌ Error: server.py not found. Make sure you are in the root of the cloned repository.")
    else:
        try:
            install_dependencies()
            print("βœ… Dependencies installed.")
            start_ngrok()
        except Exception as e:
            print(f"❌ Error: {e}")