Spaces:
Running
HuggingPost โ Full Context
What it is: Self-hosted Postiz v2.11.3 on Hugging Face Spaces. Social media scheduler with multi-channel posting (8 platforms work immediately, 12+ need OAuth setup).
Architecture:
- HF Space: single public port 7860 (health-server.js)
- Internal: nginx:5000 โ Postiz 4 PM2 procs (backend:3000, frontend:4200, workers, cron)
- Postgres + Redis internal
- Optional HF Dataset backup + sync loop
Critical Issues Fixed
1. Font build hang (FIXED)
Problem: next build tried to fetch fonts from fonts.gstatic.com โ blocked/throttled on HF โ timeout โ build never completes โ container won't start.
Solution: Vendor 4 woff2 files + runtime patch in start.sh:
- Fonts:
vendor/fonts/PlusJakartaSans-{500,600}-{normal,italic}.woff2 - Patch script:
vendor/patch-jakarta-font.jsrewrites two layout.tsx files fromnext/font/googletonext/font/local - Dockerfile Stage 2: copies fonts + patch script to
/opt/vendor/ - start.sh: detects if patch not applied (old cached image), applies it before frontend build
Commit: fd4cae0 (font patch)
2. Blank white page at /app/ (FIXED)
Root cause: HF Spaces reverse proxy intercepts absolute redirects to its own hostname, resolves them server-side, returns 200 (not 307). Next.js redirects to /auth as https://somratpro-huggingpost.hf.space/auth โ proxy resolves it โ blank 200 page.
Solution: Two fixes in health-server.js + Dockerfile:
rewriteLocation()function converts absolute URLs (internal or SPACE_HOST) to relative/apppaths so browser does the navigation- Nginx patch: fix
proxy_set_header X-Forwarded-Prototo use HF proxy's value, not internal scheme
Commits: 57b8b04 (Location rewrite + nginx fix), 245f89d (dashboard rewrite)
3. OAuth client_id=undefined (NOT A BUG)
LinkedIn/X/etc. OAuth links show client_id=undefined because env vars not set as HF Space secrets. User needs to create developer apps, add keys as secrets, restart. New dashboard guides users through this.
Files Changed
Dockerfile
- Stage 2, after postiz-builder COPY block: copy vendor fonts + patch script to
/opt/vendor/ - nginx.conf patch:
- Add
/appprefix when proxying to Next.js (line 160:proxy_pass http://127.0.0.1:4200/app/;) - Fix x-forwarded-proto (line 162: use
$http_x_forwarded_protonot$scheme)
- Add
start.sh
- Lines 172โ187: Runtime font patch block
- If layout.tsx still has
next/font/google, copy fonts, run patch script - Idempotent โ skips if already patched
- Happens before
next buildso no network calls
- If layout.tsx still has
health-server.js
getSocialPlatforms()(lines 51โ98): Array of all channels with ready status, setup URLs, env var names- 8 "works immediately" (Bluesky, Mastodon, Telegram, Dev.to, Hashnode, Nostr, Lemmy, Warpcast)
- 12 "needs OAuth" (LinkedIn, X, Facebook, Instagram, Threads, YouTube, TikTok, Reddit, Pinterest, Discord, Slack)
rewriteLocation()(lines 465โ505): Converts Location headers from Postiz- Matches internal hosts (127.0.0.1, localhost) or SPACE_HOST
- Converts absolute URLs to
/app-prefixed relative paths
renderDashboard()(lines 176โ446): Complete rewrite- Open Postiz button (disabled during boot, auto-activates when running)
- Status badges: Postiz, Uptime, Backup
- 4-step getting-started guide
- "Works immediately" section (8 platforms, collapsible)
- "Needs API keys" section (OAuth platforms, shows count configured, direct links to dev portals)
- "System & Backup" section (sync status, uptime monitor)
- Auto-refresh JS every 30s updates button state + badge states
- Deep-link to HF Space settings using SPACE_ID env var
Vendor files (new):
vendor/fonts/PlusJakartaSans-500-normal.woff2,-500-italic,-600-normal,-600-italicvendor/patch-jakarta-font.js
Current State
โ Working:
- Font patch applied at build time (Dockerfile) + runtime fallback (start.sh)
- Next.js frontend builds successfully (~5 min first boot, <1 min with cached .next from backup)
- Blank
/app/screen fixed โ middleware redirects work, browser navigates correctly - nginx routes work: /api โ backend, /uploads โ fs, / โ frontend
- Dashboard shows platform status, guides users through setup
- HF_TOKEN secret no longer leaks in startup banner
Deployment
All changes pushed to:
- GitHub:
somratpro/HuggingPost(main branch) - HF Space:
somratpro/HuggingPost(auto-synced)
HF rebuilds automatically when Dockerfile or start.sh changes.