Fastify runs on a single port, so it distinguishes incoming requests by the Host
header (the domain the client is requesting).
You can inspect the domain in each request and route or respond differently based on that.
The server listens on port 3000 for all domains pointing to this server.
It checks request.headers.host
to determine the domain.
Then routes are handled conditionally by domain + path.
You can extend logic to serve different content or proxy requests internally.
If you want better separation and cleaner code, you can register plugins conditionally:
Note: The above dynamic plugin registration inside hooks is not very typical and may cause some issues, but illustrates domain-based modular routing.
Use Nginx to route domain requests to different ports on the same server.
Run multiple Fastify instances on different ports for each domain or route group.
If you want, I can help you write full production-ready config or with reverse proxy setup. What fits your case?
Do you want Fastify to handle everything, or use Nginx as proxy?