n8n / start.py
ryusei7's picture
Create start.py
e8b11ed verified
Raw
History Blame Contribute Delete
839 Bytes
import os
import subprocess
import time
import threading
# 1. Auto-detect the Hugging Face Space URL
repo = os.getenv('HF_SPACE_ID', 'user/space')
parts = repo.split('/')
url = f'https://{parts[0].lower()}-{parts[1].lower()}.hf.space/'
# 2. Build the configuration environment
env = os.environ.copy()
env.update({
'N8N_PORT': '7860',
'N8N_DATABASE_TYPE': 'sqlite',
'N8N_USER_FOLDER': '/data/.n8n',
'N8N_ENCRYPTION_KEY': 'auto-generated-hf-n8n-key-998877',
'WEBHOOK_URL': url,
'N8N_EDITOR_BASE_URL': url
})
# 3. Print a clean, clear box in the logs with your exact link
def print_link():
time.sleep(5)
print("\n" + "="*60)
print(f"๐Ÿ‘‰ CLICK YOUR DIRECT LINK HERE: {url}")
print("="*60 + "\n")
threading.Thread(target=print_link).start()
# 4. Launch n8n
subprocess.run(['n8n', 'start'], env=env)