fastify-vhost1.1.3 • Public • Published
Proxy subdomain http requests to another server.
fastify plugin forwards all the requests
received with a given subdomain to an upstream.
fastify-vhost is powered by the popular Nodejitsu
This plugin can be used if you want to point multiple (sub)domains to the same IP address, while running different servers on the same machine.
firstname.lastname@example.org we only supported
email@example.com. We are proud to announce that
fastify-vhost now supports both v1 and v2!
npm i fastify-vhost fastify
const Fastify =const server =serverserver
This will proxy any request to the
test subdomain to the server running at
http://localhost:3000. For instance
http://test.example.com/users will be proxied to
If you want to have different vhosts for different subdomains you can register multiple instances of the plugin as shown in the following snippet:
const Fastify =const server =const vhost =serverserverserver
Notice that it is CRITICAL to provide the full
host (subdomain + domain) so that it properly routes the requests across different upstreams.
For other examples, see
fastify plugin supports the following options.
Note that this plugin is fully encapsulated and payloads will be streamed directly to the destination.
An URL (including protocol) that the requests will be forwarded to (eg. http://localhost:3000).
The host to mount this plugin on. All the requests to the current server where the
host header matches this string will be proxied to the provided upstream.
Default: false. When strict mode is enabled, the host header has to be an exact match. When disabled, 'EXAMPLE.COM', 'example.com' and 'example.com:3000' will match 'example.com'.
Default: 30000. Timeout in milliseconds for the proxy to return a
504 Gateway Timeout.
None yet. But you're welcome to open a PR.
Despite not offering ES5 support (no tests for it, or whatsoever), we'll keep it available. Although we don't recommend it, if you need / want to give it a try, import fastify-vhost like this
require('fastify-vhost/es5') instead of
- Add unit tests
- Add integration tests
- Coverage 100%
- Add benchmarks