somratpro commited on
Commit
e10105c
Β·
1 Parent(s): f398dc5

refactor: update proxy logic and n8n configuration to host application at root instead of /app/ prefix

Browse files
Files changed (3) hide show
  1. README.md +32 -15
  2. health-server.js +14 -3
  3. start.sh +2 -2
README.md CHANGED
@@ -21,9 +21,9 @@ secrets:
21
  - ⚑ **Zero Config:** Duplicate this Space, set `HF_TOKEN`, and you're ready.
22
  - πŸ’Ύ **Persistent Backup:** Workflows and credentials back up automatically to a private HF Dataset.
23
  - πŸ” **Secure by Default:** Uses n8n v2's built-in user management. No more insecure environment variables.
24
- - 🐳 **Docker Native:** Optimized for the free HF Spaces tier.
25
- - 🌐 **Dashboard UI:** Beautiful management interface at the root URL.
26
- - ⏰ **Built-in Keep-Alive:** Easily setup UptimeRobot from the dashboard.
27
 
28
  ## πŸš€ Quick Start
29
 
@@ -31,29 +31,46 @@ secrets:
31
 
32
  [![Duplicate this Space](https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-xl.svg)](https://huggingface.co/spaces/somratpro/Hugging8n?duplicate=true)
33
 
34
- ### Step 2: Add Your HF_TOKEN
35
 
36
- Add your HuggingFace token with **write** access to the Space Secrets. This enables automatic backup so your workflows aren't lost on restart.
 
37
 
38
- ### Step 3: Set Up Auth
39
 
40
- When the Space starts, visit the URL and click **Open n8n Editor**. On the first run, n8n will ask you to create an owner account. **This is your primary login.**
 
 
41
 
42
- ## πŸ” Authentication
43
 
44
- Hugging8n uses n8n's native user management.
 
 
 
 
 
 
 
45
 
46
- 1. The first person to visit `/app/` on a fresh install becomes the owner.
47
- 2. If you are restoring from a backup, your existing user accounts will be active.
 
 
 
 
48
 
49
  ## πŸ’Ύ Persistent Backup
50
 
51
- Your data is synced to a private dataset named `hugging8n-backup` in your HF account.
 
 
52
 
53
  ## πŸ—οΈ Architecture
54
 
55
- - `/` : Premium Dashboard (Status, Uptime, Keep-Alive setup)
56
- - `/app/` : n8n Workflow Editor
57
- - `/health` : Health check endpoint
58
 
 
59
  *Made with ❀️ by [@somratpro](https://github.com/somratpro)*
 
21
  - ⚑ **Zero Config:** Duplicate this Space, set `HF_TOKEN`, and you're ready.
22
  - πŸ’Ύ **Persistent Backup:** Workflows and credentials back up automatically to a private HF Dataset.
23
  - πŸ” **Secure by Default:** Uses n8n v2's built-in user management. No more insecure environment variables.
24
+ - 🌐 **Premium Dashboard:** Live status monitoring, uptime tracking, and integrated keep-alive tools.
25
+ - ⏰ **Built-in Keep-Alive:** Easily setup UptimeRobot directly from the dashboard UI.
26
+ - 🐳 **Optimized Infrastructure:** Clean startup logs, minimal resource usage, and production-ready proxy.
27
 
28
  ## πŸš€ Quick Start
29
 
 
31
 
32
  [![Duplicate this Space](https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-xl.svg)](https://huggingface.co/spaces/somratpro/Hugging8n?duplicate=true)
33
 
34
+ ### Step 2: Configure Secrets
35
 
36
+ Go to **Settings > Secrets** and add:
37
+ - `HF_TOKEN`: Your HuggingFace token with **Write** access.
38
 
39
+ ### Step 3: Initialize n8n
40
 
41
+ 1. Wait for the Space to build.
42
+ 2. Visit the Space URL and click **Open n8n Editor**.
43
+ 3. Create your owner account (this is your primary login).
44
 
45
+ ## βš™οΈ Configuration
46
 
47
+ You can customize Hugging8n using Environment Variables (Settings > Variables):
48
+
49
+ | Variable | Default | Description |
50
+ | :--- | :--- | :--- |
51
+ | `SYNC_INTERVAL` | `180` | Backup frequency in seconds. |
52
+ | `GENERIC_TIMEZONE` | `UTC` | Timezone for n8n. |
53
+ | `N8N_LOG_LEVEL` | `error` | Set to `info` for more verbose logs. |
54
+ | `SPACE_HOST_OVERRIDE` | - | Override the detected host if using a custom domain. |
55
 
56
+ ## πŸ” Authentication & Security
57
+
58
+ Hugging8n uses n8n's native user management.
59
+ - The first person to visit `/app/` on a fresh install becomes the **Owner**.
60
+ - **Important:** If you delete the Space and haven't set up `HF_TOKEN`, your users and workflows will be lost.
61
+ - **Permissions:** The startup script uses `umask 0077` to ensure all sensitive data is restricted to the node user.
62
 
63
  ## πŸ’Ύ Persistent Backup
64
 
65
+ Hugging8n automatically creates and maintains a private dataset in your Hugging Face account named `hugging8n-backup`.
66
+ - **Sync Status:** You can check the current sync health directly on the Hugging8n Dashboard.
67
+ - **Restoration:** On every startup, Hugging8n pulls the latest state from your dataset before launching n8n.
68
 
69
  ## πŸ—οΈ Architecture
70
 
71
+ - `/` : **Premium Dashboard** (Management & Monitoring)
72
+ - `/app/` : **n8n Workflow Editor**
73
+ - `/health` : **Health Check** (Used by the internal proxy and external monitors)
74
 
75
+ ---
76
  *Made with ❀️ by [@somratpro](https://github.com/somratpro)*
health-server.js CHANGED
@@ -299,8 +299,14 @@ const server = http.createServer(async (req, res) => {
299
  );
300
  }
301
 
302
- // Proxy to n8n (pass full path as n8n is configured with N8N_PATH=/app/)
303
- const proxyPath = pathname;
 
 
 
 
 
 
304
  const proxyHeaders = {
305
  ...req.headers,
306
  host: `127.0.0.1:${TARGET_PORT}`,
@@ -337,7 +343,12 @@ const server = http.createServer(async (req, res) => {
337
 
338
  server.on("upgrade", (req, socket, head) => {
339
  const url = parseRequestUrl(req.url);
340
- const proxyPath = url.pathname;
 
 
 
 
 
341
  const proxySocket = net.connect(TARGET_PORT, TARGET_HOST, () => {
342
  proxySocket.write(
343
  `${req.method} ${proxyPath}${url.search} HTTP/${req.httpVersion}\r\n`,
 
299
  );
300
  }
301
 
302
+ // Proxy to n8n
303
+ // We strip the /app prefix if present, as n8n will be configured with N8N_PATH=/
304
+ let proxyPath = pathname;
305
+ if (proxyPath.startsWith(APP_BASE)) {
306
+ proxyPath = proxyPath.substring(APP_BASE.length);
307
+ }
308
+ if (!proxyPath.startsWith("/")) proxyPath = "/" + proxyPath;
309
+
310
  const proxyHeaders = {
311
  ...req.headers,
312
  host: `127.0.0.1:${TARGET_PORT}`,
 
343
 
344
  server.on("upgrade", (req, socket, head) => {
345
  const url = parseRequestUrl(req.url);
346
+ let proxyPath = url.pathname;
347
+ if (proxyPath.startsWith(APP_BASE)) {
348
+ proxyPath = proxyPath.substring(APP_BASE.length);
349
+ }
350
+ if (!proxyPath.startsWith("/")) proxyPath = "/" + proxyPath;
351
+
352
  const proxySocket = net.connect(TARGET_PORT, TARGET_HOST, () => {
353
  proxySocket.write(
354
  `${req.method} ${proxyPath}${url.search} HTTP/${req.httpVersion}\r\n`,
start.sh CHANGED
@@ -15,8 +15,8 @@ mkdir -p "$N8N_HOME"
15
  SPACE_HOST_DETECTED="${SPACE_HOST_OVERRIDE:-${SPACE_HOST:-}}"
16
  if [ -n "$SPACE_HOST_DETECTED" ]; then
17
  export N8N_HOST="${N8N_HOST:-$SPACE_HOST_DETECTED}"
18
- # Updated for /app base path
19
- export N8N_PATH="/app/"
20
  export WEBHOOK_URL="${WEBHOOK_URL:-https://${SPACE_HOST_DETECTED}/app/}"
21
  export N8N_EDITOR_BASE_URL="${N8N_EDITOR_BASE_URL:-https://${SPACE_HOST_DETECTED}/app/}"
22
  fi
 
15
  SPACE_HOST_DETECTED="${SPACE_HOST_OVERRIDE:-${SPACE_HOST:-}}"
16
  if [ -n "$SPACE_HOST_DETECTED" ]; then
17
  export N8N_HOST="${N8N_HOST:-$SPACE_HOST_DETECTED}"
18
+ # n8n runs at / internally; proxy handles /app prefix stripping
19
+ export N8N_PATH="/"
20
  export WEBHOOK_URL="${WEBHOOK_URL:-https://${SPACE_HOST_DETECTED}/app/}"
21
  export N8N_EDITOR_BASE_URL="${N8N_EDITOR_BASE_URL:-https://${SPACE_HOST_DETECTED}/app/}"
22
  fi