{"_id":"express-subdomain","_rev":"60-39cc69b4c776bceee399c63706b7d9ef","name":"express-subdomain","description":"Simple and lightweight middleware to handle subdomains","dist-tags":{"latest":"1.0.6"},"versions":{"0.0.1":{"name":"express-subdomain","version":"0.0.1","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan"},"license":"ISC","bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@0.0.1","dist":{"shasum":"d0b68e9a265d61ae071a99d1ee9a55a0e1341051","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-0.0.1.tgz","integrity":"sha512-UyPgqHSdX1R7UkKkMS03A413lUdzTlcLFDaWLdUb3kSxiGLqBBsqzXdfeioXc6QO1G8Lmhx6YS9sXRUjjL3cCA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF7t47SfxgEke4QUq0T+79wDaNJMH5YL0bfwfJjhBRTyAiAZ1GcORDG4jXONBuDj9CktJc6EgXe+EcRnIxL+QpaluA=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"0.0.2":{"name":"express-subdomain","version":"0.0.2","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan"},"license":"ISC","bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@0.0.2","dist":{"shasum":"ebb2cab4ddc479b1b6d0d785203fc19bdf03bed3","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-0.0.2.tgz","integrity":"sha512-16cxLQiiADXMUuhfKzA0HtKlBby2PwIGOZYQGcN2bTgyVfQyDyWmKw1FKOvBcmBzbBxsA6lt1kjL8hfojEL7tA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDRu4644rV9s3bnqpdGvxA8dfWoDoFTS35Hd7UORKqDXAIhAJA+aOXfYxXySG2kasw+7eZHB1cBnN/89glLpc8fo6W/"}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"0.0.4":{"name":"express-subdomain","version":"0.0.4","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./node_modules/.bin/mocha --reporter spec"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"express":"~4.1.1","mocha":"~1.18.2","request":"~2.34.0","chai":"~1.9.1","colors":"~0.6.2"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@0.0.4","dist":{"shasum":"0a93497be97b4307c26081aa4f9fa73ef6f37b7b","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-0.0.4.tgz","integrity":"sha512-zVd5ed7h8iV3CGu2wSPp4PNumDPrcdLDgnXKmx23Z790Y9drgx2XBsGWSE9dOSYVAalnYbFGa5IZwsYg1ewrAg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGV0XWrCPGxQd69XR534jXOp3JR2Zf4/8+OtCttYrx+XAiBez/pLIokj8zziDtj94RxY1dr56wPz/D2US1T00am82Q=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.0":{"name":"express-subdomain","version":"1.0.0","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"express":"~4.1.1","mocha":"~1.18.2","request":"~2.34.0","chai":"~1.9.1","colors":"~0.6.2","coveralls":"~2.10.0","mocha-lcov-reporter":"0.0.1","istanbul":"~0.2.10"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@1.0.0","dist":{"shasum":"e59a2c216bb2efca3734fcf7a47320220fbf1da7","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.0.tgz","integrity":"sha512-p7pJymAd+HakrVcMw/L2TmMy8yFNDnTrLl8DDbeT6d42iYgQTZMV2RpdBI/rxZyHiLtCYkQVaoxuD1QUPcL6ew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEV/vvEl017rAOQpwtDPbL+LWnNL1TpkPtIGljAJFlNqAiBR5E4Rgrgh8UDt9qebNX6fHxmyY0UeNsBD2iMykWlzuQ=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.1":{"name":"express-subdomain","version":"1.0.1","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"express":"~4.1.1","mocha":"~1.18.2","request":"~2.34.0","chai":"~1.9.1","colors":"~0.6.2","coveralls":"~2.10.0","mocha-lcov-reporter":"0.0.1","istanbul":"~0.2.10"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@1.0.1","dist":{"shasum":"2994e2d628690c18961440dea1ee2403edcdc52b","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.1.tgz","integrity":"sha512-M7uct8XhiPdbKIVoKxdldrpvQKKYleQEc/MJXGFvdMfuHOjF/c9ALWeQROkomUmybwGEd50ocmV7/2n/qJg9JQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBI4EKoFjx6WvnEFkZ5Dqk8IYBRYoLaELLXB/Af3/iDtAiB80TW3v0k9HXQ80eWAZ91P2ZEq7N19wX3nxJoLJACxZg=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.2":{"name":"express-subdomain","version":"1.0.2","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"express":"~4.1.1","mocha":"~1.18.2","request":"~2.34.0","chai":"~1.9.1","colors":"~0.6.2","coveralls":"~2.10.0","mocha-lcov-reporter":"0.0.1","istanbul":"~0.2.10"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@1.0.2","dist":{"shasum":"f860990afd727e318e0bc5e6018668b73e0e7cd9","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.2.tgz","integrity":"sha512-I8DHQ4VSlJt8aU4mBdD0ZPdb1Y7WnE0mh7dNfAM3HM7CR3ijNn++o/9S2w1wJUhr7zy9EEmV+GLW6X0/1l0iuQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC1mIj2l/7BzXcwodM9gQmYym+kH3+9J4jJQ84qv+tTfQIgCxoM8N2wOvX6o+ddQI8McDxMQh1qLnqCrJx4ohQjaE0="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.3":{"name":"express-subdomain","version":"1.0.3","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"express":"~4.1.1","mocha":"~1.18.2","request":"~2.34.0","chai":"~1.9.1","colors":"~0.6.2","coveralls":"~2.10.0","mocha-lcov-reporter":"0.0.1","istanbul":"~0.2.10"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain","_id":"express-subdomain@1.0.3","dist":{"shasum":"ce38f5b49cfa4a1701b46d4dcfacae277125fa84","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.3.tgz","integrity":"sha512-/46KQ1OBEs37gwLSwqAwryEWoAfhKb/0TqfCMW+i4nq5/n9g3RRKHsaengnZMtpJsdtj2kpzcY8nwNEpJMSqiA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCb7daZlTve5RVzUBsJK/2q27zgjfw8QIrHWOw5B7d57QIhALOLg7snM3lMuOJUKoJz8CIJwwU0GkUCtQ/NLboeQZfq"}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.4":{"name":"express-subdomain","version":"1.0.4","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"chai":"~1.9.1","colors":"~0.6.2","composable-middleware":"^0.3.0","coveralls":"~2.10.0","express":"~4.1.1","istanbul":"~0.2.10","mocha":"~1.18.2","mocha-lcov-reporter":"0.0.1","request":"~2.34.0"},"gitHead":"bca136366242b1e7f36a4eaa1c693ab9cf5025af","bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain#readme","_id":"express-subdomain@1.0.4","_shasum":"1dcd4265ba532e5452ce5b6ad2a3305b40289a2d","_from":".","_npmVersion":"2.14.1","_nodeVersion":"0.10.38","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"dist":{"shasum":"1dcd4265ba532e5452ce5b6ad2a3305b40289a2d","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.4.tgz","integrity":"sha512-H5NFRqQH2OawRrVNz38JG/uc8h7ngnsTw0NlDu4a/unfGDE+J1lT8BIDrs5n5cnJB5vJ8iHSYTOl/UTZPLX3tA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBKp4pUErMgb0M7UTeqzfTFgFpgCcowCvOLpfMJ8CMxsAiEAwR54wTsQVYatOsmBgl7zit2szKJqH0NLulwG2H9Hpo4="}]},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"directories":{}},"1.0.5":{"name":"express-subdomain","version":"1.0.5","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"chai":"~1.9.1","colors":"~0.6.2","composable-middleware":"^0.3.0","coveralls":"~2.10.0","express":"~4.1.1","istanbul":"~0.2.10","mocha":"~1.18.2","mocha-lcov-reporter":"0.0.1","request":"~2.34.0"},"gitHead":"66da15d5f08ceca779f35caf076289c5739ff74b","bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain#readme","_id":"express-subdomain@1.0.5","_shasum":"990ef97940b7f4c2823d9593648b79be858a638b","_from":".","_npmVersion":"2.14.8","_nodeVersion":"0.10.38","_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"dist":{"shasum":"990ef97940b7f4c2823d9593648b79be858a638b","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.5.tgz","integrity":"sha512-tpYy7MPgDoouxA4r+BnGI43yxYakbSSpQn7MjEYM0ssHeipTM1YiIoK3i4pCAgoXoks22Yb5C4QFkOYBYczZcw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHKS2RTZXf0QVVn0hpHJri3dpqZ5kwuof6BA0NwqP9jeAiEAnl+P0cqcq/0r71/3uGKfm9DJWsf7O/dVcKOhcIuxVbY="}]},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"_npmOperationalInternal":{"host":"packages-6-west.internal.npmjs.com","tmp":"tmp/express-subdomain-1.0.5.tgz_1455927095444_0.3376742780674249"},"directories":{}},"1.0.6":{"name":"express-subdomain","version":"1.0.6","repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"description":"Simple and lightweight middleware to handle subdomains","main":"index.js","types":"index.d.ts","scripts":{"test":"./test/pre-script.sh; ./node_modules/.bin/mocha --reporter spec; ./test/post-script.sh","coverage":"./test/pre-script.sh; istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage; ./test/post-script.sh"},"keywords":["express","express-subdomain","subdomain"],"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"license":"MIT","devDependencies":{"chai":"~1.9.1","colors":"~0.6.2","composable-middleware":"^0.3.0","coveralls":"~2.10.0","express":"~4.1.1","istanbul":"~0.2.10","mocha":"~1.18.2","mocha-lcov-reporter":"0.0.1","request":"~2.34.0"},"_id":"express-subdomain@1.0.6","gitHead":"a97a6bb18c3ea0a09d3e9dcf6a9d15aeef58e27d","bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"homepage":"https://github.com/bmullan91/express-subdomain#readme","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-A51MvQhk5L3aDV4s5XcKrn5I0bCFOk95xikJjlDWNUrtiAaCjy44RjvBz4uLRH0nCvt8Y3SKt1EvxUUmGJ5QRQ==","shasum":"df9a0ba337482de302be25f88afefe05ba976a8c","tarball":"https://registry.npmjs.org/express-subdomain/-/express-subdomain-1.0.6.tgz","fileCount":17,"unpackedSize":26819,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAz1HGMxmiwaQmJmeICxXX9WzbkoMwk6hzKx2TBIAkR6AiEA2kK/9rhFi/70WX3D8yycPO9rgw5yDIKfL694Gbglci0="}]},"_npmUser":{"name":"bmullan91","email":"bmullan91@gmail.com"},"directories":{},"maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-subdomain_1.0.6_1706737802354_0.9784713996988752"},"_hasShrinkwrap":false}},"readme":"[![Build Status](https://travis-ci.org/bmullan91/express-subdomain.svg?branch=master)](https://travis-ci.org/bmullan91/express-subdomain) [![Coverage Status](https://coveralls.io/repos/bmullan91/express-subdomain/badge.png?branch=master)](https://coveralls.io/r/bmullan91/express-subdomain?branch=master)\n\n# express-subdomain\n\nIs simply express middleware. In the examples below I am using [Express v4.x](http://expressjs.com/).\n\n## Install\n\nWith npm, saving it as a dependency.\n\n    npm i express-subdomain --save\n\n## Simple usage\n\nLet's say you want to provide a RESTful API via the url `http://api.example.com`\n\n#### Express boilerplate code:\n\n``` js\nvar subdomain = require('express-subdomain');\nvar express = require('express');\nvar app = express();\n\n// *** Code examples below go here! ***\n\n// example.com\napp.get('/', function(req, res) {\n    res.send('Homepage');\n});\n\n```\n\n#### API Router\n\n``` js\nvar router = express.Router();\n\n//api specific routes\nrouter.get('/', function(req, res) {\n    res.send('Welcome to our API!');\n});\n\nrouter.get('/users', function(req, res) {\n    res.json([\n        { name: \"Brian\" }\n    ]);\n});\n```\n\nNow register the subdomain middleware:\n``` js\napp.use(subdomain('api', router));\napp.listen(3000);\n```\nThe API is alive:\n\n`http://api.example.com/` --> \"Welcome to our API!\"\n\n`http://api.example.com/users` --> \"[{\"name\":\"Brian\"}]\"\n\n\n## Multi-level Subdomains\n\n``` js\napp.use(subdomain('v1.api', router)); //using the same router\n```\n\n`http://v1.api.example.com/` --> \"Welcome to our API!\"\n\n`http://v1.api.example.com/users` --> \"[{\"name\":\"Brian\"}]\"\n\n### Wildcards\n\nSay you wanted to ensure that the user has an API key before getting access to it... and this is across __all__ versions.\n\n_Note_:\nIn the example below, the passed function to subdomain can be just a pure piece of middleware.\n\n``` js\nvar checkUser = subdomain('*.api', function(req, res, next) {\n    if(!req.session.user.valid) {\n        return res.send('Permission denied.');\n    }\n    next();\n});\n\napp.use(checkUser);\n```\n\nThis can be used in tandem with the examples above.\n\n_Note_:\nThe order in which the calls to app.use() is very important. Read more about it [here](http://expressjs.com/4x/api.html#app.use).\n\n``` js\napp.use(checkUser);\napp.use(subdomain('v1.api', router));\n```\n\n## Divide and Conquer\n\nThe subdomains can also be chained, for example to achieve the same behaviour as above:\n\n``` js\nvar router = express.Router(); //main api router\nvar v1Routes = express.Router();\nvar v2Routes = express.Router();\n\nv1Routes.get('/', function(req, res) {\n    res.send('API - version 1');\n});\nv2Routes.get('/', function(req, res) {\n    res.send('API - version 2');\n});\n\nvar checkUser = function(req, res, next) {\n    if(!req.session.user.valid) {\n        return res.send('Permission denied.');\n    }\n    next();\n};\n\n//the api middleware flow\nrouter.use(checkUser);\nrouter.use(subdomain('*.v1', v1Routes));\nrouter.use(subdomain('*.v2', v2Routes));\n\n//basic routing..\nrouter.get('/', function(req, res) {\n    res.send('Welcome to the API!');\n});\n\n//attach the api\napp.use(subdomain('api', router));\napp.listen(3000);\n```\n\n#### Invalid user\n\n`http://api.example.com/` --> Permission denied.\n\n#### Valid user\n\n`http://api.example.com/` --> Welcome to the API!\n\n`http://v1.api.example.com/` --> API - version 1\n\n`http://abc.v1.api.example.com/` --> API - version 1\n\n`http://v2.api.example.com/` --> API - version 2\n\n`http://abc.v2.api.example.com/` --> API - version 2\n\n## Developing Locally\n\nIf you plan to use this middleware while developing locally, you'll have to\nensure that your subdomain is listed in your hosts file.\n\nOn Linux or OSX, add your subdomain to `/etc/hosts`:\n```\n127.0.0.1       myapp.dev\n127.0.0.1       subdomain.myapp.dev\n```\n\nYou may not have write permissions on your hosts file, in which case you can\ngrant them:\n```\n$ sudo chmod a+rw /etc/hosts\n```\n\n_Note_:\nExpress parses the request URL for a top level domain, so developing locally\nwithout one won't be possible because Express will treat the subdomain as the\ndomain, and the actual domain as a TLD.\n\n#### Windows\n\nOn Windows 7 and 8, the hosts file path is `%systemroot%\\system32\\drivers\\etc`.\n\n## Gotchas\n\nMultilevel TLD's, such as `.co.uk` you have to pass `api.example` as the _subdomain_:\n\n```js\napp.use(subdomain('api.example', router));\n```\nSee https://github.com/bmullan91/express-subdomain/issues/17 for more info.\n\n## Need in-depth examples?\n\nHave a look at the [tests](https://github.com/bmullan91/express-subdomain/tree/master/test)!\n","maintainers":[{"name":"bmullan91","email":"bmullan91@gmail.com"}],"time":{"modified":"2024-01-31T21:50:02.757Z","created":"2014-04-26T23:05:38.258Z","0.0.1":"2014-04-26T23:05:38.258Z","0.0.2":"2014-04-27T14:27:57.270Z","0.0.4":"2014-05-03T11:41:36.385Z","1.0.0":"2014-06-11T19:13:53.573Z","1.0.1":"2014-09-16T19:04:19.345Z","1.0.2":"2014-11-07T21:01:48.839Z","1.0.3":"2015-01-31T13:10:04.236Z","1.0.4":"2015-09-26T21:37:46.771Z","1.0.5":"2016-02-20T00:11:40.568Z","1.0.6":"2024-01-31T21:50:02.560Z"},"homepage":"https://github.com/bmullan91/express-subdomain#readme","keywords":["express","express-subdomain","subdomain"],"repository":{"type":"git","url":"git://github.com/bmullan91/express-subdomain.git"},"author":{"name":"Brian Mullan","email":"bmullan91@gmail.com"},"bugs":{"url":"https://github.com/bmullan91/express-subdomain/issues"},"license":"MIT","readmeFilename":"README.md","users":{"bjrmatos":true,"bam5":true,"mdpauley":true,"ramirex":true,"leanardnoir":true,"thomask33":true,"gedarufi":true,"iwatakeshi":true,"markthethomas":true,"yizen":true,"hengkiardo":true,"tarkeshwar":true,"dwayneford":true,"tuiteraz":true,"sonhuytran":true,"dyaa":true,"kalock":true,"itskdk":true,"forthright48":true,"jcottam":true,"max_devjs":true,"chrisx":true,"landy2014":true,"rocket0191":true,"slurm":true,"cslasher":true,"fabioper":true,"drdoof":true,"errohitagg":true,"lwdthe1":true,"incipi":true,"demian_dark":true,"bytescrafter":true}}