Node.js / Express
Configure Express, Fastify, or plain Node.js servers to work behind Hatch.
Map your domain
hatch add api.test 8000 --https
Host binding
Make sure your server listens on 0.0.0.0 (all interfaces), not just 127.0.0.1. Most frameworks default to 0.0.0.0 already, but if you're specifying a host explicitly:
// Express
app.listen(8000, '0.0.0.0');
// Fastify
fastify.listen({ port: 8000, host: '0.0.0.0' });
// Plain Node.js
server.listen(8000, '0.0.0.0');Trust proxy
Hatch sets X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host headers. To use them in your app (e.g. for req.ip or req.protocol):
// Express
app.set('trust proxy', 'loopback');
// Fastify
fastify.register(require('@fastify/under-pressure'));
// Fastify trusts proxy headers with trustProxy option
const fastify = Fastify({ trustProxy: true });CORS
If your Node.js API is called from a frontend on a different Hatch domain (e.g. frontend on app.test, API on api.test), configure CORS:
// Express with cors package
const cors = require('cors');
app.use(cors({
origin: 'https://app.test',
credentials: true,
}));Project config
# .hatch.yaml
domains:
- domain: api.test
port: 8000
https: true