{ "_args": [ [ { "raw": "vhost@~3.0.1", "scope": null, "escapedName": "vhost", "name": "vhost", "rawSpec": "~3.0.1", "spec": ">=3.0.1 <3.1.0", "type": "range" }, "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/connect" ] ], "_from": "vhost@>=3.0.1 <3.1.0", "_id": "vhost@3.0.2", "_inCache": true, "_location": "/vhost", "_npmUser": { "name": "dougwilson", "email": "doug@somethingdoug.com" }, "_npmVersion": "1.4.28", "_phantomChildren": {}, "_requested": { "raw": "vhost@~3.0.1", "scope": null, "escapedName": "vhost", "name": "vhost", "rawSpec": "~3.0.1", "spec": ">=3.0.1 <3.1.0", "type": "range" }, "_requiredBy": [ "/connect" ], "_resolved": "https://registry.npmjs.org/vhost/-/vhost-3.0.2.tgz", "_shasum": "2fb1decd4c466aa88b0f9341af33dc1aff2478d5", "_shrinkwrap": null, "_spec": "vhost@~3.0.1", "_where": "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/connect", "bugs": { "url": "https://github.com/expressjs/vhost/issues" }, "contributors": [ { "name": "Douglas Christopher Wilson", "email": "doug@somethingdoug.com" }, { "name": "Jonathan Ong", "email": "me@jongleberry.com", "url": "http://jongleberry.com" } ], "dependencies": {}, "description": "virtual domain hosting", "devDependencies": { "istanbul": "0.3.22", "mocha": "2.3.3", "supertest": "1.1.0" }, "directories": {}, "dist": { "shasum": "2fb1decd4c466aa88b0f9341af33dc1aff2478d5", "tarball": "https://registry.npmjs.org/vhost/-/vhost-3.0.2.tgz" }, "engines": { "node": ">= 0.8.0" }, "files": [ "LICENSE", "HISTORY.md", "index.js" ], "gitHead": "2dff3f358265380328067d1ffc91e342b665f586", "homepage": "https://github.com/expressjs/vhost#readme", "license": "MIT", "maintainers": [ { "name": "tootallnate", "email": "nathan@tootallnate.net" }, { "name": "jongleberry", "email": "jonathanrichardong@gmail.com" }, { "name": "dougwilson", "email": "doug@somethingdoug.com" }, { "name": "tjholowaychuk", "email": "tj@vision-media.ca" }, { "name": "mscdex", "email": "mscdex@mscdex.net" }, { "name": "fishrock123", "email": "fishrock123@rocketmail.com" }, { "name": "defunctzombie", "email": "shtylman@gmail.com" }, { "name": "TooTallNate", "email": "nathan@tootallnate.net" } ], "name": "vhost", "optionalDependencies": {}, "readme": "# vhost\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![Gratipay][gratipay-image]][gratipay-url]\n\n## Install\n\n```sh\n$ npm install vhost\n```\n\n## API\n\n```js\nvar vhost = require('vhost')\n```\n\n### vhost(hostname, handle)\n\nCreate a new middleware function to hand off request to `handle` when the incoming\nhost for the request matches `hostname`. The function is called as\n`handle(req, res, next)`, like a standard middleware.\n\n`hostname` can be a string or a RegExp object. When `hostname` is a string it can\ncontain `*` to match 1 or more characters in that section of the hostname. When\n`hostname` is a RegExp, it will be forced to case-insensitive (since hostnames are)\nand will be forced to match based on the start and end of the hostname.\n\nWhen host is matched and the request is sent down to a vhost handler, the `req.vhost`\nproperty will be populated with an object. This object will have numeric properties\ncorresponding to each wildcard (or capture group if RegExp object provided) and the\n`hostname` that was matched.\n\n```js\n// for match of \"foo.bar.example.com:8080\" against \"*.*.example.com\":\nreq.vhost.host === 'foo.bar.example.com:8080'\nreq.vhost.hostname === 'foo.bar.example.com'\nreq.vhost.length === 2\nreq.vhost[0] === 'foo'\nreq.vhost[1] === 'bar'\n```\n\n## Examples\n\n### using with connect for static serving\n\n```js\nvar connect = require('connect')\nvar serveStatic = require('serve-static')\nvar vhost = require('vhost')\n\nvar mailapp = connect()\n\n// add middlewares to mailapp for mail.example.com\n\n// create app to serve static files on subdomain\nvar staticapp = connect()\nstaticapp.use(serveStatic('public'))\n\n// create main app\nvar app = connect()\n\n// add vhost routing to main app for mail\napp.use(vhost('mail.example.com', mailapp))\n\n// route static assets for \"assets-*\" subdomain to get\n// around max host connections limit on browsers\napp.use(vhost('assets-*.example.com', staticapp))\n\n// add middlewares and main usage to app\n\napp.listen(3000)\n```\n\n### using with connect for user subdomains\n\n```js\nvar connect = require('connect')\nvar serveStatic = require('serve-static')\nvar vhost = require('vhost')\n\nvar mainapp = connect()\n\n// add middlewares to mainapp for the main web site\n\n// create app that will server user content from public/{username}/\nvar userapp = connect()\n\nuserapp.use(function(req, res, next){\n var username = req.vhost[0] // username is the \"*\"\n\n // pretend request was for /{username}/* for file serving\n req.originalUrl = req.url\n req.url = '/' + username + req.url\n\n next()\n})\nuserapp.use(serveStatic('public'))\n\n// create main app\nvar app = connect()\n\n// add vhost routing for main app\napp.use(vhost('userpages.local', mainapp))\napp.use(vhost('www.userpages.local', mainapp))\n\n// listen on all subdomains for user pages\napp.use(vhost('*.userpages.local', userapp))\n\napp.listen(3000)\n```\n\n### using with any generic request handler\n\n```js\nvar connect = require('connect')\nvar http = require('http')\nvar vhost = require('vhost')\n\n// create main app\nvar app = connect()\n\napp.use(vhost('mail.example.com', function (req, res) {\n // handle req + res belonging to mail.example.com\n res.setHeader('Content-Type', 'text/plain')\n res.end('hello from mail!')\n}))\n\n// an external api server in any framework\nvar httpServer = http.createServer(function (req, res) {\n res.setHeader('Content-Type', 'text/plain')\n res.end('hello from the api!')\n})\n\napp.use(vhost('api.example.com', function (req, res) {\n // handle req + res belonging to api.example.com\n // pass the request to a standard Node.js HTTP server\n httpServer.emit('request', req, res)\n}))\n\napp.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/vhost.svg\n[npm-url]: https://npmjs.org/package/vhost\n[travis-image]: https://img.shields.io/travis/expressjs/vhost/master.svg\n[travis-url]: https://travis-ci.org/expressjs/vhost\n[coveralls-image]: https://img.shields.io/coveralls/expressjs/vhost/master.svg\n[coveralls-url]: https://coveralls.io/r/expressjs/vhost\n[downloads-image]: https://img.shields.io/npm/dm/vhost.svg\n[downloads-url]: https://npmjs.org/package/vhost\n[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg\n[gratipay-url]: https://gratipay.com/dougwilson/\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/expressjs/vhost.git" }, "scripts": { "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" }, "version": "3.0.2" }