{"id":14989663,"url":"https://github.com/equim-chan/koa-virtual-host","last_synced_at":"2026-03-01T12:03:33.799Z","repository":{"id":107319061,"uuid":"86846046","full_name":"Equim-chan/koa-virtual-host","owner":"Equim-chan","description":":zap: A name-based virtual host middleware for Koa2.","archived":false,"fork":false,"pushed_at":"2018-09-18T09:57:27.000Z","size":17,"stargazers_count":16,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T02:47:53.000Z","etag":null,"topics":["javascript","koa","koa2","middleware","nodejs","server","vhost"],"latest_commit_sha":null,"homepage":"","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/Equim-chan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-31T17:52:50.000Z","updated_at":"2023-08-11T00:06:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"76433252-fe94-4034-8d37-0ccf14f7cfc9","html_url":"https://github.com/Equim-chan/koa-virtual-host","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"39b50f3fc962a5dc4eb12ebcda116bb4cfc5e3dd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Equim-chan/koa-virtual-host","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fkoa-virtual-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fkoa-virtual-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fkoa-virtual-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fkoa-virtual-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Equim-chan","download_url":"https://codeload.github.com/Equim-chan/koa-virtual-host/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equim-chan%2Fkoa-virtual-host/sbom","scorecard":{"id":46308,"data":{"date":"2025-08-11","repo":{"name":"github.com/Equim-chan/koa-virtual-host","commit":"39b50f3fc962a5dc4eb12ebcda116bb4cfc5e3dd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-14T22:51:33.018Z","repository_id":107319061,"created_at":"2025-08-14T22:51:33.018Z","updated_at":"2025-08-14T22:51:33.018Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29969243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T11:43:06.159Z","status":"ssl_error","status_checked_at":"2026-03-01T11:43:03.887Z","response_time":124,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","koa","koa2","middleware","nodejs","server","vhost"],"created_at":"2024-09-24T14:18:43.609Z","updated_at":"2026-03-01T12:03:28.785Z","avatar_url":"https://github.com/Equim-chan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-virtual-host\n[![npm version](https://img.shields.io/npm/v/koa-virtual-host.svg?style=flat)](https://www.npmjs.com/package/koa-virtual-host)\n[![node version](https://img.shields.io/node/v/koa-virtual-host.svg?style=flat)](https://www.npmjs.com/package/koa-virtual-host)\n[![Build Status](https://img.shields.io/travis/Equim-chan/koa-virtual-host.svg?style=flat)](https://travis-ci.org/Equim-chan/koa-virtual-host)\n[![Coverage Status](https://img.shields.io/coveralls/Equim-chan/koa-virtual-host.svg?style=flat)](https://coveralls.io/github/Equim-chan/koa-virtual-host?branch=master)\n[![VersionEye](https://img.shields.io/versioneye/d/user/projects/58deaba3d6c98d004405475e.svg)](https://www.versioneye.com/user/projects/58deaba3d6c98d004405475e)\n[![Codacy Badge](https://img.shields.io/codacy/grade/9f4a3b6990134a7b9c5fe099dfb41bcd.svg?style=flat)](https://www.codacy.com/app/Equim-chan/koa-virtual-host)\n[![license](https://img.shields.io/npm/l/koa-virtual-host.svg?style=flat)](https://github.com/Equim-chan/koa-virtual-host/blob/master/LICENSE)\n\nA name-based virtual host middleware for Koa2.\n\n## Installation\n``` shell\n$ npm i --save koa-virtual-host\n```\n\n## Example\n``` javascript\nconst Koa = require('koa');\nconst vhost = require('koa-virtual-host');\n\n// Import sub Koa apps\nconst api = require('./apps/api');\nconst apex = require('./apps/apex');\nconst blog = require('./apps/blog');\nconst forum = require('./apps/forum');\nconst resume = require('./apps/resume');\nconst unicode = require('./apps/unicode');\n\n// Set up a host\nconst host = new Koa();\n\n/**\n * Configure vhosts\n */\n\n// Support string patterns\nhost.use(vhost('blog.example.com', blog));\n\n// Support regexp patterns\nhost.use(vhost(/^(?:pro.*|resume)\\.example\\.com$/i, resume));\n\n// Support pattern-app mappings as object\nhost.use(vhost({\n  'example.org': apex,\n  'forum.example.com': forum\n}));\n\n// Support pattern-app mappings as array of objects\nhost.use(vhost([{\n  pattern: /^b(?:bs|oard)\\.example\\..+$/i,\n  target: forum\n}, {\n  pattern: 'api.example.com',\n  target: api\n}]));\n\n// Support Unicode hostname\n// Support many-to-one mappings\nhost.use(vhost('中文域名.com', unicode));\nhost.use(vhost(/(?:萌|moe)/, unicode));\nhost.use(vhost(/[\\u4E00-\\u9FFF]\\.io/, unicode));\n\n// Support basic global controls serving as a usual Koa app\nhost.use(async (ctx, next) =\u003e {\n  ctx.set('Server', 'Koa Virtual Host');\n  await next();\n});\n\n// Listen and enjoy\nhost.listen(80);\n```\n\n## API\n### vhost(pattern, target)\n\n* pattern (`String` | `RegExp`) - the pattern used to match the hostname\n* target (`Object`) - the Koa app\n\nExample:\n``` javascript\nconst Koa = require('koa');\nconst vhost = require('koa-virtual-host');\n\n// You can also import them from existing modules that export ones.\nconst a = new Koa();\nconst b = new Koa();\n\na.use(async (ctx, next) =\u003e {\n  ctx.body = 'Hello';\n  await next();\n});\n\nb.use(async (ctx, next) =\u003e {\n  ctx.body = 'World';\n  await next();\n});\n\nconst host = new Koa();\n\n// The requests that match the pattern will be forwarded to the corresponding app.\nhost.use(vhost(/localhost/i, a));\nhost.use(vhost('127.0.0.1', b));\n\nhost.listen(8000);\n```\n\nTry to request:\n``` shell\n$ curl http://localhost:8000/\nHello\n\n$ curl http://127.0.0.1:8000/\nWorld\n```\n\n### vhost(patterns)\n\n* patterns (`Object` | `Array`) - the pattern-app map\n\nNotes that if you pass an `Object` to `patterns`, RegExp patterns will not be supported. To enable RegExp support, you need to pass an `Array`.\n\nExample:\n``` javascript\nconst Koa = require('koa');\nconst vhost = require('koa-virtual-host');\n\nconst a = new Koa();\nconst b = new Koa();\nconst c = new Koa();\nconst d = new Koa();\n\na.use(async (ctx, next) =\u003e {\n  await next();\n  ctx.body += ' World';\n});\n\nb.use(async (ctx, next) =\u003e {\n  ctx.body = 'Hello';\n  await next();\n});\n\nc.use(async (ctx, next) =\u003e {\n  await next();\n  ctx.set('X-Powered-By', 'Koa');\n});\n\nd.use(async (ctx, next) =\u003e {\n  ctx.body = 'foobar';\n  await next();\n  ctx.set('X-Powered-By', 'vhost');\n});\n\nconst host = new Koa();\n\nhost.use(vhost({\n  'localhost': a,\n  '127.0.0.1': c\n}));\n\n// Additionally, if the pattern is duplicated,\n// the corresponding apps will be called in order\nhost.use(vhost([{\n  pattern: 'localhost',\n  target: b\n}, {\n  pattern: /^127\\.0\\.0\\.\\d+$/,\n  target: d\n}]));\n\nhost.listen(8000);\n```\n\nTry to request:\n``` shell\n$ curl http://localhost:8000/\nHello World\n\n$ curl http://127.0.0.1:8000/\nfoobar\n\n$ curl -I http://127.0.0.1:8000/ 2\u003e\u00261 | grep \"X-Powered-By\"\nX-Powered-By: Koa\n```\n## Test\n``` shell\n$ npm test\n```\n\n## License\n[MIT](https://github.com/Equim-chan/koa-virtual-host/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequim-chan%2Fkoa-virtual-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fequim-chan%2Fkoa-virtual-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequim-chan%2Fkoa-virtual-host/lists"}