portless-service-integration
Skill2 starsChanged 10 months agoMITView on GitHub
Use when wiring a local development service (dev server, preview server, static site, any long-running HTTP upstream) to portless so it gets a stable `.localhost` URL instead of a port number. Also use when user says "portless", "replace ports with names", "stable localhost URL", ".localhost domain", "portless proxy", "PORTLESS_*" env vars, "sin puerto", or when integrating portless into Makefile targets or package.json scripts. Covers proxy setup, naming conventions, env vars, troubleshooting (including the cert-0-bytes stuck state), and points to ecosystem-specific references (Python, Node/Vite/Storybook, Go) loaded on demand.
- Reads credentials
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- cendoj-toolkitSkill
- contract-first-clean-archSkill
- drawio-uml-shapesSkill
- expert-panelSkill
- huly-apiSkill
- makefile-service-conventionsSkill
- repo-kickstartSkill
- service-managerSkill
- validating-skillsSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 1 is distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 92
Do NOT write proxy-alive checks in Makefiles: before invoking portless <name> <cmd> — the command itself handles auto-start.
- Distinctive: line 125
NOT a second route: two names for one component means which one answers depends on what happens to be running.
- Very specific: line 130
When you run portless <name> <cmd>, portless sets these env vars for the child:
- Very specific: line 148
If your tool doesn't read PORT automatically, pass it explicitly:
- Very specific: line 241
Avoid .dev (Google-owned, HSTS-forced in browsers) and .local (collides with mDNS/Bonjour).
- Very specific: line 260
Run portless doctor first — it checks the proxy, the routes, DNS resolution and CA trust in one pass, and points at the failing layer …
- Very specific: line 278
If you see a .pem file with size 0, portless failed to sign the CSR silently:
- Very specific: line 302
Impact of proxy restart: all other active routes need their parent processes to re-run (they'll re-register on next portless <name> <cmd>).
- Very specific: line 308
If curl http://127.0.0.1:<port>/ works but curl https://<name>.localhost/ fails with SSL_ERROR_SYSCALL, the issue is almost always the cert.
- Very specific: line 313
If portless list shows -> localhost:4321 and your upstream binds to ::1:4321 but portless connects to 127.0.0.1:4321, the upstream is …
- Very specific: line 338
If service A (e.g. Vite with /api proxy) forwards to service B without rewriting the Host header, portless routes back to A → loop.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Portless Service Integration
portless (npm package) replaces port numbers with stable .localhost URLs. Instead of memorizing
localhost:5173 vs localhost:4321 vs localhost:8765, each service gets a named URL like
dev.ps.myorg.localhost. Same URL across restarts, profiles, and machines.
Value proposition:
- Zero port conflicts across projects
- Stable URLs in bookmarks, docs, and
.envfiles - Cookies and localStorage isolated per service (no clashes at
localhost:X) - HTTPS with HTTP/2 out of the box (via local CA)
- Language-agnostic (works with any process that speaks HTTP on a TCP port)
This skill is deliberately ecosystem-agnostic. Load an ecosystem-specific reference for concrete patterns:
references/python-uvicorn.md— Python ASGI servers (uvicorn + starlette, aiohttp). Do NOT usepython -m http.serverbehind portless — see reference for why.references/vite-storybook.md— Vite, Storybook, Astro, Next, and other Node frameworks where portless auto-injects--port/--host.references/go-net-http.md— Gonet/httpservices (stdlib is HTTP/1.1 keep-alive by default).
Workflow
digraph portless_flow {
rankdir=TB;
"Proxy auto-starts" [shape=box, style=filled, fillcolor="#d7e1d8"];
"Pick service name" -> "Choose invocation mode";
"Choose invocation mode" -> "portless <name> <cmd>" [label="managed lifecycle"];
"Choose invocation mode" -> "portless alias <name> <port>" [label="pre-running / Docker"];
"Choose invocation mode" -> "portless run <cmd>" [label="infer name from package.json or git"];
"portless <name> <cmd>" -> "Access via <name>.localhost";
"portless alias <name> <port>" -> "Access via <name>.localhost";
"portless run <cmd>" -> "Access via <inferred>.localhost";
}Step 1: Proxy setup (auto-starts, rarely manual)
Portless runs a background proxy that binds .localhost → your ports. It auto-starts the first
time you run portless <name> <cmd> or portless run <cmd>. Manual start is only needed for
specific scenarios.
# Start HTTPS proxy on port 443 (requires sudo first time — installs local CA)
portless proxy start
# HTTP-only on port 80 (no sudo, no TLS)
portless proxy start --no-tls
# Custom proxy port (no sudo, no special privileges)
portless proxy start -p 1355
# Foreground for debugging
portless proxy start --foreground
# Stop proxy
portless proxy stop
# Health check — proxy, routes, DNS, CA trust in one pass (0.15.0+)
portless doctor
# Start the proxy automatically when the OS starts
portless service install
# Kill orphaned dev servers left behind by crashed sessions
portless prunePortless requires Node 24+ (since 0.13.1). Since 0.15.4 the proxy binds loopback-only unless LAN mode is explicitly enabled — dev services are not exposed to the network by default.
Do NOT write proxy-alive checks in Makefiles before invoking portless <name> <cmd> — the
command itself handles auto-start. Checks like lsof -iTCP:443 -sTCP:LISTEN are unreliable because
privileged port owners may not be visible without root, and return false negatives.
Step 2: Naming convention (component first)
[<worktree>.]<component>.<environment>.<project>.<owner>.localhostThe first thing you read is the thing you are looking at — the way public DNS reads
(api.github.com, not prod.api.github.com). Five axes:
component: WHAT answers at the URL —app,core,storybook,preview,dashboard, ... Name the responsibility, not the interface (core, notapi).environment: a real taxonomy, not a synonym for "local" —localdev(a developer's machine),dev(a SHARED deployed dev server),qa,preprod,prod. A URL served from a laptop islocaldev, neverdev.project: project short name (myapp)owner: org/tenant namespace (myorg,acme) — drop it for single-org setupsworktree: composed BY PORTLESS, never by your Makefile.portless run --name <base>keeps the base name on the main checkout and prepends the branch as the LEFTMOST label in a linked git worktree (0.15.5+), so presence is detected by label count, not position.
Examples (using myorg as the owner):
app.localdev.myapp.myorg.localhost— the app, on a developer's machinecore.localdev.myapp.myorg.localhost— the domain service behind itstorybook.localdev.myapp.myorg.localhost— the component workshopfix-ui.app.localdev.myapp.myorg.localhost— same app, linked worktree on branchfix-ui(prefix added by portless, zero Makefile involvement)
A mode toggle (mock vs real backend, feature profile) is an env var flowing into the child process, NOT a second route: two names for one component means which one answers depends on what happens to be running.
Step 3: Env vars portless injects into child processes
When you run portless <name> <cmd>, portless sets these env vars for the child:
PORT— ephemeral port (4000-4999 range) the child must listen onHOST— always127.0.0.1(IPv4). The proxy connects upstream to this addressPORTLESS_URL— the public URL (e.g.https://myapp.localhost) for cross-service refs
Upstream must bind to 127.0.0.1 (IPv4 explicit). The docs are clear on this. If your server
binds to localhost and the OS resolves it to IPv6 (::1), portless can't reach it — you'll see
the TLS handshake fail with SSL_ERROR_SYSCALL at the proxy edge (proxy never logs the request).
Does your tool respect PORT env var?
- Yes (by convention): Next.js, Express, Nuxt, uvicorn (when you pass
--port "$PORT"), most mature servers - No (portless auto-injects
--portand--hostflags): Vite, Astro, React Router, Angular, Expo, React Native - No (you must wire it yourself):
python -m http.server,ruby -run -e httpd, any custom CLI
If your tool doesn't read PORT automatically, pass it explicitly:
portless myapp sh -c 'exec <tool> --port "$PORT" --host 127.0.0.1 ...'Step 4: Invocation modes
Mode A — Managed lifecycle (most common)
portless app.localdev.myapp vite
# → https://app.localdev.myapp.localhost
# Portless assigns PORT, launches vite, registers route
# Worktree-aware variant (branch prefixed as leftmost label in linked worktrees):
portless run --name app.localdev.myapp viteMode B — Infer name from project
cd my-project
portless run vite
# → https://my-project.localhost (inferred from package.json or git root)Mode C — Static alias (pre-running services, Docker)
# Service already listens on a fixed port (e.g. PostgreSQL at 5432)
portless alias my-postgres 5432
# → https://my-postgres.localhost → 127.0.0.1:5432Alias is for services portless does not launch (Docker, system services, already-running processes). For services you want portless to manage, use Mode A.
Mode D — Get URL for cross-service reference
BACKEND_URL=$(portless get backend)
# → https://backend.localhostStep 5: Wiring into Makefile or package.json
Portless composes with standard tooling. No abstraction layer (like a service-manager.ts) is required — it's a plain CLI command you invoke.
Directly in Makefile target
serve: generate
@portless dashboard.localdev.myapp <command>In package.json
{
"scripts": {
"dev": "portless run vite"
}
}Then pnpm dev gets the portless URL without config duplication.
Bypass portless for CI / scripted runs
PORTLESS=0 pnpm dev # runs command directly on its default portStep 6: DNS resolution — .localhost auto-resolves
Modern macOS, Linux, and Windows resolve *.localhost to 127.0.0.1 automatically per RFC
6761. No /etc/hosts entries needed. This works out of the box with curl, ping, Chrome,
Firefox, Edge.
Exceptions that may need /etc/hosts sync:
- Safari: relies on system resolver and can miss certain subdomain configurations
- Custom TLD (
--tld test):.testdoes not auto-resolve; portless auto-syncs/etc/hostswhen you use it
Custom TLD rules (0.15.1+):
--tldis repeatable andPORTLESS_TLDtakes a comma-separated list. Multi-TLD serves the SAME app names under every TLD — not different apps under different ones.PORTLESS_URLcarries the first.- Since 0.15.5 a TLD may be multi-segment (
--tld internal.acme), so local URLs can mirror production structure. Labels are DNS-validated; overlapping TLDs resolve longest-match. - Avoid
.dev(Google-owned, HSTS-forced in browsers) and.local(collides with mDNS/Bonjour)..testis IANA-reserved and safe, but needs the hosts sync above. - LAN mode ignores a custom TLD — it serves under
.local; the two cannot be combined.
Manual sync:
portless hosts sync # Write current routes to /etc/hosts
portless hosts clean # Remove portless entries from /etc/hostsEnvironment flag to enable auto-sync for .localhost:
export PORTLESS_SYNC_HOSTS=1Step 7: Troubleshooting
Run portless doctor first — it checks the proxy, the routes, DNS resolution and CA trust in one
pass, and points at the failing layer before you start guessing.
Cert stuck at 0 bytes (most common stuck state)
Symptoms:
curlreturnsLibreSSL SSL_connect: SSL_ERROR_SYSCALL- Proxy log (
/tmp/portless/proxy.log) has no entry for the failed request (the TLS handshake dies before the proxy logs the upstream attempt) - Other portless routes work fine
Diagnosis:
ls -la /tmp/portless/host-certs/ | grep <my-host>If you see a .pem file with size 0, portless failed to sign the CSR silently:
-rw-r--r-- root 219 myapp_myorg_localhost-ext.cnf
-rw------- root 227 myapp_myorg_localhost-key.pem
-rw-r--r-- root 391 myapp_myorg_localhost.csr
-rw-r--r-- root 0 myapp_myorg_localhost.pem ← BUG: empty certFix (quirúrgico):
# 1. Remove the corrupt cert files (owned by root, need sudo)
sudo rm /tmp/portless/host-certs/<my-host>*
# 2. Restart the proxy (regenerates certs on next request)
portless proxy stop
portless proxy start
# 3. Verify
curl -sS -I https://<my-host>.localhost/
# Expected: HTTP/2 200 + x-portless: 1Impact of proxy restart: all other active routes need their parent processes to re-run (they'll
re-register on next portless <name> <cmd>). If that's too disruptive, try step 1 alone first and
let portless regenerate on next request.
Upstream reachable directly but not via proxy
If curl http://127.0.0.1:<port>/ works but curl https://<name>.localhost/ fails with
SSL_ERROR_SYSCALL, the issue is almost always the cert. See above.
IPv4/IPv6 mismatch
If portless list shows -> localhost:4321 and your upstream binds to ::1:4321 but portless
connects to 127.0.0.1:4321, the upstream is unreachable. Always bind upstreams to 127.0.0.1
explicitly — don't use localhost (which may resolve to ::1) or 0.0.0.0 (works but exposes
the service on all interfaces). Since 0.15.2 an IPv6-only upstream no longer 502s, but explicit
127.0.0.1 remains the convention here — it is what the proxy dials first and it keeps the service
off the LAN.
Proxy log location
/tmp/portless/proxy.log # daemon log
/tmp/portless/host-certs/ # per-host certs
/tmp/portless/routes.json # registered routes
/tmp/portless/ca.srl, ca.pem # local CATail during a failing request to capture the live error:
tail -f /tmp/portless/proxy.log &
curl https://<my-host>.localhost/Infinite loop between portless apps
If service A (e.g. Vite with /api proxy) forwards to service B without rewriting the Host
header, portless routes back to A → loop. Portless detects this and responds with
508 Loop Detected. Fix: in your frontend framework's proxy config, set changeOrigin: true (Vite,
webpack-dev-server).
Common mistakes
| Mistake | Correct approach |
Bind upstream to localhost (may resolve to ::1) | Bind to 127.0.0.1 explicit |
Bind to 0.0.0.0 in dev | Use 127.0.0.1 (matches portless + doesn't expose to LAN) |
Manual proxy-alive check in Makefile before portless <cmd> | Trust auto-start; portless handles it |
Use portless alias for services you launch yourself | Use portless <name> <cmd> (managed lifecycle) |
Assume .localhost needs /etc/hosts entries | Modern OS resolvers handle *.localhost per RFC 6761 |
Wrap everything in service-manager.ts abstraction | Direct portless calls in Makefile / package.json work fine |
Use python -m http.server behind portless | See references/python-uvicorn.md — use uvicorn instead |
Use --no-tls on :443 (http on :443) | Stick with default HTTPS on :443 for browser compat |
| Ignore 0-byte cert files silently | Check /tmp/portless/host-certs/ when TLS fails — fix per Step 7 |
Related skills
makefile-service-conventions— canonical Makefile targets (start/stop/restart/status, aggregate AND per-service…/<svc>— the full quartet is mandatory per service) that wire into portless.restartis part of the primary set; for managed (Mode A) routes a naiverestartis the classic breaker —stopmust whole-tree-kill the route's process AND clean by route pid beforestartre-registers (idempotentstartrequired); a Mode C alias just re-runsalias --remove+alias.service-manager— optional higher-level orchestrator when you have many services with PID tracking needs (not required for portless use)repo-kickstart— bootstrap a new project with portless wired in
Ecosystem-specific references
Load these on demand when working with a specific stack:
- Python servers:
references/python-uvicorn.md - Vite / Storybook / Node frameworks:
references/vite-storybook.md - Go services:
references/go-net-http.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

