Share localhost / Express
Share an Express app at a public URL
An Express app listens on the port you give app.listen, 3000 in the docs' hello world, and whk share 3000 gives that port an HTTPS link. Express checks no host, so every route answers at once. What it gets wrong until you tell it about the proxy is the protocol, the hostname and the client address.
# terminal 1: the dev server
node app.js
# terminal 2: the link
whk share 3000The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.
Express at a glance
- Dev server
node app.js, port 3000- Share it
whk share 3000- Setting to add
- No host setting.
app.set('trust proxy', 'loopback')so Express readsX-Forwarded-*from the link. - Without it
- No error.
req.protocolishttp,req.hostnameislocalhost,req.ipis127.0.0.1, and a session cookie markedsecure: trueis never set. - Hot reload
- Express has no reload of its own. Restart tools restart the server, and visitors see the change on their next request.
- URLs and cookies
- With
trust proxy,req.hostnameandreq.hostare the public name,req.protocolishttpsandreq.ipis the visitor.req.get('host')stayslocalhost:3000.
Your dev server gets each request with Host: localhost:3000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.
Tell Express it is behind a proxy
By default Express treats itself as facing the client directly: req.protocol comes from the socket, req.hostname from the Host header and req.ip from the connection. Through the link those are http, localhost and 127.0.0.1, because the request reaches your app from whk on your own machine.
The trust proxy setting tells Express which addresses may speak for the client. whk connects from loopback, so trust loopback and nothing wider:
app.js
const express = require("express");
const app = express();
// whk share connects from this machine
app.set("trust proxy", "loopback");Now req.protocol is https, req.secure is true, req.hostname is <name>.sharehooks.cc and req.ip is the visitor's address. req.host (which keeps a port in Express 5) follows too. req.get('host') reads the raw header and still says localhost:3000, so build absolute URLs from req.protocol and req.host.
Secure session cookies
express-session does not set a cookie marked secure: true on a connection it believes is plain HTTP. Without trust proxy that is every request through the link, and the symptom is a login that never sticks: the response simply carries no Set-Cookie.
With trust proxy set as above, the session cookie goes out with Secure and the visitor's browser, which is on HTTPS, keeps it. cookie: { secure: 'auto' } picks the right value on localhost and on the link alike. Leave the cookie's domain unset: a cookie for another domain is dropped on the way out.
Redirects, WebSockets and reloads
res.redirect('/login') sends a path, which works on any origin. A redirect to http://localhost:3000/... is also returned to the link. WebSocket servers attached to the same HTTP server, ws or Socket.IO among them, come through on the same port.
There is no dev server in Express and so no browser reload: tools that restart Node on change restart your app, and a visitor's next request reaches the new code. If nothing is listening during a restart, the visitor gets a short page saying so rather than a broken connection.
Express questions
Start the app, then run whk share with its port, for example whk share 3000. The CLI prints an HTTPS link on sharehooks.cc that reaches your app until you press Ctrl-C. Express needs no host setting for requests to be answered.
loopback. The tunnel client connects from 127.0.0.1 or ::1, and app.set('trust proxy', 'loopback') trusts exactly those addresses. true trusts any address, which lets any client that can reach the port directly forge X-Forwarded headers.
The cookie is marked secure and Express thinks the request is plain HTTP, because TLS ends at the link. Set trust proxy so X-Forwarded-Proto: https is believed, or use cookie.secure: 'auto' in express-session.
Only with trust proxy set. Without it req.hostname comes from the Host header, which through whk share is localhost. With it, req.hostname comes from X-Forwarded-Host, the preview's name.
Sources
The Express settings and messages on this page are from the official documentation for Express 5.3, read on 12 November 2026. What the link does to a request is from the whk share docs.
Other frameworks
Send someone your Express app
Sign up free, install the CLI and run whk share 3000.
No credit card