Leon4gr45 commited on
Commit
3a20637
·
verified ·
1 Parent(s): d217b5b

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +50 -17
start.sh CHANGED
@@ -133,46 +133,79 @@ else
133
  fi
134
 
135
 
136
-
137
  # --- n8n Start (as n8nuser) ---
138
  echo "--- n8n Setup (running as $(whoami)) ---"
139
 
140
- # Check for essential secrets first
141
  if [ -z "$N8N_ENCRYPTION_KEY" ]; then
142
- echo "ERROR: N8N_ENCRYPTION_KEY is not set. Please set it as a Space secret."
143
  exit 1
144
  fi
145
  if [ -z "$DB_POSTGRESDB_PASSWORD" ]; then
146
- echo "ERROR: DB_POSTGRESDB_PASSWORD is not set. Please set it as a Space secret."
147
- exit 1 # This check might be redundant if PG setup already exited, but good for clarity
148
  fi
149
 
150
- # Set up n8n environment variables
151
  export N8N_USER_FOLDER="/home/n8nuser/.n8n"
152
- export GENAI_MODELS_N8N_DEFAULT_MODEL="$DEFAULT_MODEL" # DEFAULT_MODEL is from Ollama section
153
- export DB_POSTGRESDB_PORT="$POSTGRES_PORT" # POSTGRES_PORT is from PostgreSQL section
154
 
155
- # Security headers for Hugging Face embedding
156
- export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="^https?:\/\/([a-zA-Z0-9\-]+\.)*hf\.space$"
157
- export N8N_SEC_ALLOW_ALL_ORIGINS_FOR_WEBHOOKS="true"
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- # Enable task runners (recommended by n8n deprecation notice)
160
  export N8N_RUNNERS_ENABLED="true"
161
 
162
- # Configure URLs if HF_SPACE_HOST_WITH_PROTOCOL is available
163
  if [ -n "$HF_SPACE_HOST_WITH_PROTOCOL" ]; then
164
  export WEBHOOK_URL="$HF_SPACE_HOST_WITH_PROTOCOL/"
165
  export N8N_EDITOR_BASE_URL="$HF_SPACE_HOST_WITH_PROTOCOL/"
166
- echo "N8N URLs set for Hugging Face Space: $N8N_EDITOR_BASE_URL"
167
  elif [ -n "$SPACE_HOST" ]; then
168
- # Fallback using SPACE_HOST if available
169
  DERIVED_URL="https://$SPACE_HOST/"
170
  export WEBHOOK_URL="$DERIVED_URL"
171
  export N8N_EDITOR_BASE_URL="$DERIVED_URL"
172
  echo "N8N URLs derived from SPACE_HOST: $N8N_EDITOR_BASE_URL"
173
  else
174
- echo "Warning: Neither HF_SPACE_HOST_WITH_PROTOCOL nor SPACE_HOST found. n8n URLs may not be set optimally."
175
  fi
176
 
177
  echo "Starting n8n..."
178
- exec n8n start # This is the single, final command to start n8n
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  fi
134
 
135
 
 
136
  # --- n8n Start (as n8nuser) ---
137
  echo "--- n8n Setup (running as $(whoami)) ---"
138
 
 
139
  if [ -z "$N8N_ENCRYPTION_KEY" ]; then
140
+ echo "ERROR: N8N_ENCRYPTION_KEY is not set."
141
  exit 1
142
  fi
143
  if [ -z "$DB_POSTGRESDB_PASSWORD" ]; then
144
+ echo "ERROR: DB_POSTGRESDB_PASSWORD is not set."
145
+ exit 1
146
  fi
147
 
 
148
  export N8N_USER_FOLDER="/home/n8nuser/.n8n"
149
+ export GENAI_MODELS_N8N_DEFAULT_MODEL="$DEFAULT_MODEL"
150
+ export DB_POSTGRESDB_PORT="$POSTGRES_PORT"
151
 
152
+ # --- Embedding Configuration ---
153
+ # Option A: General hf.space (Try this first)
154
+ # This regex allows embedding from any subdomain of hf.space.
155
+ HF_SPACE_DOMAIN_REGEX="^https?:\/\/([a-zA-Z0-9\-]+\.)*hf\.space$"
156
+
157
+ # Option B: Very Specific to your Space URL (If Option A doesn't work)
158
+ # Replace 'leon4gr45-n8n-suite.hf.space' with your exact space URL if different.
159
+ # SPECIFIC_SPACE_URL_REGEX="^https:\/\/leon4gr45-n8n-suite\.hf\.space$"
160
+
161
+ # CHOOSE ONE REGEX:
162
+ # Uncomment the one you want to use for N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX
163
+ # export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="$SPECIFIC_SPACE_URL_REGEX"
164
+ export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="$HF_SPACE_DOMAIN_REGEX"
165
+ # --- End Embedding Configuration ---
166
 
167
+ export N8N_SEC_ALLOW_ALL_ORIGINS_FOR_WEBHOOKS="true"
168
  export N8N_RUNNERS_ENABLED="true"
169
 
 
170
  if [ -n "$HF_SPACE_HOST_WITH_PROTOCOL" ]; then
171
  export WEBHOOK_URL="$HF_SPACE_HOST_WITH_PROTOCOL/"
172
  export N8N_EDITOR_BASE_URL="$HF_SPACE_HOST_WITH_PROTOCOL/"
173
+ echo "N8N URLs set via HF_SPACE_HOST_WITH_PROTOCOL: $N8N_EDITOR_BASE_URL"
174
  elif [ -n "$SPACE_HOST" ]; then
 
175
  DERIVED_URL="https://$SPACE_HOST/"
176
  export WEBHOOK_URL="$DERIVED_URL"
177
  export N8N_EDITOR_BASE_URL="$DERIVED_URL"
178
  echo "N8N URLs derived from SPACE_HOST: $N8N_EDITOR_BASE_URL"
179
  else
180
+ echo "Warning: Neither HF_SPACE_HOST_WITH_PROTOCOL nor SPACE_HOST found."
181
  fi
182
 
183
  echo "Starting n8n..."
184
+ exec n8n start
185
+
186
+
187
+
188
+ IGNORE_WHEN_COPYING_START
189
+ Use code with caution. Bash
190
+ IGNORE_WHEN_COPYING_END
191
+
192
+ How to Use the Options:
193
+
194
+ Try Option A first: The line export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="$HF_SPACE_DOMAIN_REGEX" is already active in the script above. This is generally robust.
195
+
196
+ If Option A still doesn't work, then try Option B:
197
+
198
+ Comment out: # export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="$HF_SPACE_DOMAIN_REGEX"
199
+
200
+ Uncomment: export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX="$SPECIFIC_SPACE_URL_REGEX"
201
+
202
+ Make sure leon4gr45-n8n-suite.hf.space in SPECIFIC_SPACE_URL_REGEX exactly matches your Space's hostname.
203
+
204
+ The Most "Forceful" (but less secure and for testing/diagnosis only):
205
+ If neither of the above works, and you want to see if n8n's mechanism is responding at all, you could temporarily allow embedding from anywhere. This is not recommended for a live or public Space due to security risks (clickjacking).
206
+
207
+
208
+ # FOR DIAGNOSTIC PURPOSES ONLY - INSECURE
209
+ # export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX=".*"
210
+
211
+