| # Hugging Face Spaces provides SPACE_HOST as an environment variable | |
| # (e.g., your-username-your-space-name.hf.space). | |
| # We must set WEBHOOK_URL for n8n to correctly generate public URLs for webhooks. | |
| if [ -n "$SPACE_HOST" ]; then | |
| # Ensure the URL scheme is https as HF Spaces are served over HTTPS | |
| export WEBHOOK_URL="https://$(echo $SPACE_HOST)" | |
| echo "INFO: n8n WEBHOOK_URL automatically set to $WEBHOOK_URL" | |
| else | |
| echo "WARNING: SPACE_HOST environment variable not set. WEBHOOK_URL may not be configured correctly for public access." | |
| echo "INFO: n8n will attempt to infer the WEBHOOK_URL, or you can set it manually via environment variables." | |
| fi | |
| # --- IMPORTANT: Encryption Key --- | |
| # N8N_ENCRYPTION_KEY is crucial for securing your credentials. | |
| # If not set, n8n auto-generates one. If this auto-generated key changes (e.g., on pod restart | |
| # without persistent storage for the key itself), your previously saved credentials will be unreadable. | |
| # | |
| # YOU MUST SET N8N_ENCRYPTION_KEY as a SECRET in your Hugging Face Space settings | |
| # for any production or sensitive data use. | |
| # Generate a strong, random string for this key. E.g., using: openssl rand -hex 32 | |
| if [ -z "$N8N_ENCRYPTION_KEY" ]; then | |
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | |
| echo "!! WARNING: N8N_ENCRYPTION_KEY is NOT SET. n8n will auto-generate a temporary one. !!" | |
| echo "!! This is INSECURE for production and may lead to DATA LOSS of credentials. !!" | |
| echo "!! Please set N8N_ENCRYPTION_KEY as a Secret in your Space settings. !!" | |
| echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | |
| fi | |
| # Optional: Set other n8n environment variables here if needed, | |
| # or preferably as Secrets in your Hugging Face Space settings. | |
| # Example for basic authentication (use with caution, prefer SSO if possible): | |
| # export N8N_BASIC_AUTH_ACTIVE=true | |
| # export N8N_BASIC_AUTH_USER="your_username_secret" | |
| # export N8N_BASIC_AUTH_PASSWORD="your_strong_password_secret" | |
| echo "INFO: Starting n8n..." | |
| # Execute the main n8n command. It will pick up all N8N_* environment variables. | |
| exec n8n |