refactor: update proxy logic and n8n configuration to host application at root instead of /app/ prefix
Browse files- README.md +32 -15
- health-server.js +14 -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 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
|
| 28 |
## π Quick Start
|
| 29 |
|
|
@@ -31,29 +31,46 @@ secrets:
|
|
| 31 |
|
| 32 |
[](https://huggingface.co/spaces/somratpro/Hugging8n?duplicate=true)
|
| 33 |
|
| 34 |
-
### Step 2:
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
### Step 3:
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
##
|
| 43 |
|
| 44 |
-
Hugging8n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
## πΎ Persistent Backup
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
## ποΈ Architecture
|
| 54 |
|
| 55 |
-
- `/` : Premium Dashboard (
|
| 56 |
-
- `/app/` : n8n Workflow Editor
|
| 57 |
-
- `/health` : Health
|
| 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 |
[](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
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 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
|
|
|
|
| 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
|