{"id":16326665,"url":"https://github.com/chrisyip/koa-better-vhost","last_synced_at":"2025-05-14T22:12:14.624Z","repository":{"id":138204994,"uuid":"46653947","full_name":"chrisyip/koa-better-vhost","owner":"chrisyip","description":null,"archived":false,"fork":false,"pushed_at":"2015-11-22T15:28:20.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T22:12:14.238Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/chrisyip.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":"2015-11-22T09:26:45.000Z","updated_at":"2015-11-22T15:28:28.000Z","dependencies_parsed_at":"2023-03-13T19:35:32.375Z","dependency_job_id":null,"html_url":"https://github.com/chrisyip/koa-better-vhost","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fkoa-better-vhost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fkoa-better-vhost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fkoa-better-vhost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fkoa-better-vhost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisyip","download_url":"https://codeload.github.com/chrisyip/koa-better-vhost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235711,"owners_count":22036965,"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":[],"created_at":"2024-10-10T23:09:14.083Z","updated_at":"2025-05-14T22:12:14.602Z","avatar_url":"https://github.com/chrisyip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-better-vhost\n\n[![Node version][node-image]][npm-url] [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Travis CI][travis-image]][travis-url] [![Codecov][codecov-image]][codecov-url]\n\nvhost for koajs.\n\nForked from [koa-vhost](https://github.com/Treri/koa-vhost).\n\n# Install\n\n```js\nnpm i koa-better-vhost\n```\n\n# Example\n\n```js\nconst koa = require('koa')\nconst Router = require('koa-router')\nconst vhost = require('koa-better-vhost')\n\nconst main = koa()\nmain.use(require('koa-compress')())\nmain.use(function* (next) {\n  this.today = new Date\n  yield next\n})\n\nlet vhosts = []\n\nlet homepage = koa()\nlet homepageRouter = new Router()\nhomepageRouter.get('/', function* (next) {\n  // `this` is shared between main and homepage applications\n  this.body = `Hello ${this.today.toUTCString()}`\n  yield next\n})\n\nhomepage.use(homepageRouter.routes())\n\nvhosts.push({\n  host: 'example.com',\n  app: homepage\n})\n\nlet api = koa()\napi.use(function* auth (next) {\n  // Do some auth job\n  yield next\n})\n\nlet apiRouter = new Router()\napiRouter.get('/', function* (next) {\n  /**\n   * Because we set this vhost is isolated, `this` is NOT shared between main and api applications\n   * But `koa-compress` is still working\n   */\n  console.info(typeof this.today) // undefined\n  this.body = `Hello from API`\n  yield next\n})\napi.use(apiRouter.routes())\n\nvhosts.push({\n  host: /^api\\.example\\.com$/i,\n  app: api,\n  isolated: true\n})\n\nmain.use(vhost(vhosts))\n```\n\n[node-image]: http://img.shields.io/node/v/koa-better-vhost.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-better-vhost\n[npm-image]: http://img.shields.io/npm/v/koa-better-vhost.svg?style=flat-square\n[daviddm-url]: https://david-dm.org/chrisyip/koa-better-vhost\n[daviddm-image]: http://img.shields.io/david/chrisyip/koa-better-vhost.svg?style=flat-square\n[travis-url]: https://travis-ci.org/chrisyip/koa-better-vhost\n[travis-image]: http://img.shields.io/travis/chrisyip/koa-better-vhost.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/chrisyip/koa-better-vhost\n[codecov-image]: https://img.shields.io/codecov/c/github/chrisyip/koa-better-vhost.svg?style=flat-square\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fkoa-better-vhost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisyip%2Fkoa-better-vhost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fkoa-better-vhost/lists"}