request.hostname

The host of the incoming request, derived from the Host header.

Since Fastify 5 Spec ↗

Syntax

request.hostname

Returns

string — The request hostname, without the port.

Examples

import Fastify from 'fastify';

const app = Fastify({ trustProxy: true });

app.get('/tenant', async (req) => {
  const sub = req.hostname.split('.')[0];
  return { tenant: sub, port: req.port };
});

Notes

With `trustProxy`, the X-Forwarded-Host header is honored. request.host includes the port while request.hostname does not. Useful for multi-tenant subdomain routing.