{"id":28164021,"url":"https://github.com/patrickpissurno/fastify-vhost","last_synced_at":"2025-05-15T11:15:20.907Z","repository":{"id":32779144,"uuid":"142365890","full_name":"patrickpissurno/fastify-vhost","owner":"patrickpissurno","description":"Proxy subdomain http requests to another server","archived":false,"fork":false,"pushed_at":"2025-01-26T01:45:47.000Z","size":763,"stargazers_count":23,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T15:12:30.945Z","etag":null,"topics":["fastify","fastify-plugin","nodejs","proxy","reverse-proxy","subdomain","vhost","vhosts"],"latest_commit_sha":null,"homepage":"https://npm.im/fastify-vhost","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickpissurno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-26T00:01:38.000Z","updated_at":"2025-01-26T01:57:42.000Z","dependencies_parsed_at":"2023-02-10T17:45:14.772Z","dependency_job_id":null,"html_url":"https://github.com/patrickpissurno/fastify-vhost","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickpissurno%2Ffastify-vhost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickpissurno%2Ffastify-vhost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickpissurno%2Ffastify-vhost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickpissurno%2Ffastify-vhost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickpissurno","download_url":"https://codeload.github.com/patrickpissurno/fastify-vhost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328388,"owners_count":22052634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","nodejs","proxy","reverse-proxy","subdomain","vhost","vhosts"],"created_at":"2025-05-15T11:14:59.120Z","updated_at":"2025-05-15T11:15:20.898Z","avatar_url":"https://github.com/patrickpissurno.png","language":"JavaScript","readme":"# fastify-vhost\n[![npm-version](https://img.shields.io/npm/v/fastify-vhost.svg)](https://www.npmjs.com/package/fastify-vhost)\n[![coverage status](https://coveralls.io/repos/github/patrickpissurno/fastify-vhost/badge.svg?branch=master)](https://coveralls.io/github/patrickpissurno/fastify-vhost?branch=master)\n[![known vulnerabilities](https://snyk.io/test/github/patrickpissurno/fastify-vhost/badge.svg)](https://snyk.io/test/github/patrickpissurno/fastify-vhost)\n[![downloads](https://img.shields.io/npm/dt/fastify-vhost.svg)](https://www.npmjs.com/package/fastify-vhost)\n[![license](https://img.shields.io/github/license/patrickpissurno/fastify-vhost.svg?maxAge=1800)](https://github.com/patrickpissurno/fastify-vhost/blob/master/LICENSE)\n\nProxy subdomain http requests to another server.\nThis [`fastify`](https://www.fastify.io) plugin forwards all the requests\nreceived with a given subdomain to an upstream.\n\n`fastify-vhost` is powered by the popular Nodejitsu [`http-proxy`](https://github.com/nodejitsu/node-http-proxy). [![GitHub stars](https://img.shields.io/github/stars/nodejitsu/node-http-proxy.svg?style=social\u0026label=Star)](https://github.com/nodejitsu/node-http-proxy)\n\nThis 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.\n\n## Fastify support\nPrior to `fastify-vhost@1.1.3` we only supported `fastify@1.x.x`. We are proud to announce that `fastify-vhost` now supports both v1, v2 and v3!\n\n## Install\n\n```\nnpm i fastify-vhost fastify\n```\n\n## Example\n\n```js\nconst Fastify = require('fastify')\nconst server = Fastify()\n\nserver.register(require('fastify-vhost'), {\n  upstream: 'http://localhost:3000',\n  host: 'test.example.com'\n})\n\nserver.listen(80)\n```\n\nThis 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 `http://localhost:3000/users`.\n\nIf you want to have different vhosts for different subdomains you can register multiple instances of the plugin as shown in the following snippet:\n\n```js\nconst Fastify = require('fastify')\nconst server = Fastify()\nconst vhost = require('fastify-vhost')\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3000',\n  host: 'test.example.com'\n})\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3001',\n  host: 'other.example.com'\n})\n\nserver.listen(80)\n```\n\nYou can also specify multiple aliases for each vhost with the `hosts` option:\n\n```js\nconst Fastify = require('fastify')\nconst server = Fastify()\nconst vhost = require('fastify-vhost')\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3000',\n  hosts: ['test.example.com', 'test2.example.com']\n})\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3001',\n  host: 'other.example.com'\n})\n\nserver.listen(80)\n```\n\nThe above example would behave the same as the following:\n\n```js\nconst Fastify = require('fastify')\nconst server = Fastify()\nconst vhost = require('fastify-vhost')\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3000',\n  host: 'test.example.com'\n})\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3000',\n  host: 'test2.example.com'\n})\n\nserver.register(vhost, {\n  upstream: 'http://localhost:3001',\n  host: 'other.example.com'\n})\n\nserver.listen(80)\n```\n\nBut in a much neater way.\n\nNotice that it is **CRITICAL** to provide the full `host` (subdomain + domain) so that it properly routes the requests across different upstreams.\n\nFor other examples, see `example.js`.\n\n## Options\n\nThis `fastify` plugin supports the following options.\n\n*Note that this plugin is fully encapsulated and payloads will be streamed directly to the destination.*\n\n### upstream\n\nAn URL (including protocol) that the requests will be forwarded to (eg. http://localhost:3000).\n\n### host\n\nThe 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.\n\n### hosts\n\nEquivalent to the `host` option, but an array of strings. All the requests to the current server where the `host` header matches any of the strings will be proxied to the provided upstream.\n\n### strict\n\n```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'.\n\n### timeout\n\n```Default: 30000```. Timeout in milliseconds for the proxy to return a ```504 Gateway Timeout```.\n\n## Benchmarks\n\nNone yet. But you're welcome to open a PR.\n\n## TODO\n\n* [x] Add unit tests\n* [x] Add integration tests\n* [x] Coverage 100%\n* [ ] Add benchmarks\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickpissurno%2Ffastify-vhost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickpissurno%2Ffastify-vhost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickpissurno%2Ffastify-vhost/lists"}