{"_id":"controller","_rev":"32-13f1446b038ace318567936271ce7dc6","name":"controller","description":"an action controller for express","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"controller","version":"0.1.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"_id":"controller@0.1.0","dist":{"shasum":"1737c7625581a738f310bfc5517a803d4db67277","tarball":"https://registry.npmjs.org/controller/-/controller-0.1.0.tgz","integrity":"sha512-++m0w7vhhqj3knHXdWUQ4m8QCj44px3VCAy2Fzyz5ikGopaj6z0uMhI3gSefZCTcUpLhmyb34JB3h9DskA5PbA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDiwD16PjS5a/XvT4awRxUxlS1iS1onb+63IZC2bs6jbwIgZpG535ZaW269iX/Gso6v/EBDNjAABTRMMSD24ZJ5238="}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.2.0":{"name":"controller","version":"0.2.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"_id":"controller@0.2.0","dist":{"shasum":"b218d2bbbf3456f20707e470cf4cdf2066fbe2fd","tarball":"https://registry.npmjs.org/controller/-/controller-0.2.0.tgz","integrity":"sha512-7Qn177zG1eAAgq/qjb8tDE8s+Evun14bE5PbPWG3sELGCnx5Xbur5HHVfjcrDVuV+qlh5byd1cbuDpHZYL2jRw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDTBLAzeysVmLEyHoxVdY6CtSDPLDaC+MKXXBYMP8VWnAIhAMHoU81OgJMFuNGOdDdYnh6lVf5WE2uObvhQo5ifPFik"}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.2.1":{"name":"controller","version":"0.2.1","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"_id":"controller@0.2.1","dist":{"shasum":"b8472715299ba20bf9c7f605d5fe2a5479ffd5e3","tarball":"https://registry.npmjs.org/controller/-/controller-0.2.1.tgz","integrity":"sha512-UDnOr6sNv29T0h50Xeqo8Lw79CqsfeT2zR/Rm2qS+FED1cltYJg0d800T8eslZXVEGLSKw6LrptxHnDMa/YXjg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCeGZBIbhf1OOjnxlquX9/A92QJs86ORPCgGfBdk5+ICwIhAJGUtC1Ujixe1DwfdDG9eWyaryONckjExjNC7TvenXX3"}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.2.2":{"name":"controller","version":"0.2.2","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"_id":"controller@0.2.2","dist":{"shasum":"d99b9c6391789c4a559a106e35c687f798cc6068","tarball":"https://registry.npmjs.org/controller/-/controller-0.2.2.tgz","integrity":"sha512-iQ3FesFvWC8ChX0NGYdL9SApDydRA6abSejh7qLtm8EH5y5yj7OYkbqVnFxa3+b7C0AGMVSpuGJe4taF1cyUMw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE12XbW//YgUZNvGrI7eMPp5cbSWq4VNkMgdrgQWBBELAiEApA2mD573iQrHt/nTpJYMjQm0txus4Hm24oALJNao+so="}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.3.0":{"name":"controller","version":"0.3.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"dependencies":{"express":"~3.0.0rc2","supertest":"~0.1.2","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.3.0","dist":{"shasum":"99411fff628eb56bcf58cb054bcfd85bb68c7506","tarball":"https://registry.npmjs.org/controller/-/controller-0.3.0.tgz","integrity":"sha512-+Xf4g5s4k762Xw6u4/P4bRgFVnlWnMqrxvOj1tAH0CX/nTsiYdGdU+/2H83fNciWAAs7hrUqDRQvCuNztg9wPA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC7aKDuJFPdEmf4wb0jzsLzIeBtbdsIfIZBeTX67YeG8AiEA+najYpJ/h4FecbR4fRjj8VXvUS9vp/G/F9S2Zfbr7Ek="}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.4.0":{"name":"controller","version":"0.4.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"mocha":"*"},"dependencies":{"express":"~3.0.0rc2","supertest":"~0.1.2","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.4.0","dist":{"shasum":"497c0e80b17d2784f2b63051e77c6789d83a4c0e","tarball":"https://registry.npmjs.org/controller/-/controller-0.4.0.tgz","integrity":"sha512-jJMs91NyH9dMITMqFaynxbSy9i7ncqR3HvQlPxbR1VPGroay9bN0Hr9zKKN6DPGa8Vp9//DKaL1PKye46JtWFA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqO12qCdZXCEXdqGzziRPEwmEfeqxmLKkpOvrH8e73iAIgS6jUherp0KoaQ8mDjY0b5EjSeLFFq7SqUdrZrfVxwpk="}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.4.1":{"name":"controller","version":"0.4.1","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.0.0rc2","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.4.1","dist":{"shasum":"2d039a9bf01e547ad28154a4c9b3cc7de73d9195","tarball":"https://registry.npmjs.org/controller/-/controller-0.4.1.tgz","integrity":"sha512-nh4EYQiZr+QpQMMKcHbjFemrXHuv4a1PO58rnnEQaTo+tmosH/dYDaHFMwkiwuXn2uNZfuQ463RFXS0e4Miaag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRyIUWrb80NVrvWEYxbFxFlfZ/hCRosiBjwVQKnm1DWAIgELzPky2/tvVyTYRanRHBleJutdZiDae/x3l6z2eVCBI="}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.4.2":{"name":"controller","version":"0.4.2","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.2.0","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.4.2","dist":{"shasum":"6fb0ded403306d6e0c1b8ef5aaf9db3c5036c295","tarball":"https://registry.npmjs.org/controller/-/controller-0.4.2.tgz","integrity":"sha512-gQe1M85Jjavg9/q0Ym4kdrNfwsLQqWL6gmny3QGjwfMcKyclDUbOu/sblPbzVKCFLQnl6RAYz+Qn6lzkr57E1w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQChhloThVk2LI9A6QYe0cbLzgV0oi6SaJc2Xv9hDrJbpgIhALcHgeu6zqtlNOJc+rlJT/FIgNgVQVNxCW9+4iQEkkNG"}]},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.5.0":{"name":"controller","version":"0.5.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.4.4","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.5.0","dist":{"shasum":"cce44bc6342d11ec753de5b338a7554755e74236","tarball":"https://registry.npmjs.org/controller/-/controller-0.5.0.tgz","integrity":"sha512-SK6QMe7gC73HLBFoTbFc5uUapF6s/R4fx9vHLc18dwSuY2AJrEwLaPNwNenZdYVDgfLyTW0h18nSaph+vTRoeA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE/+O8dmGzlfalrlwbITuDteRxv4mjs8rv+6ETZPz37EAiEAriKBYv7ODdK4Lf3Sxhm4QZYi3DDfT26oFWf2SVn+npk="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.5.1":{"name":"controller","version":"0.5.1","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.4.4","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.5.1","dist":{"shasum":"e360bfec3d3142d73a382088e7fe0ee3a0f3af73","tarball":"https://registry.npmjs.org/controller/-/controller-0.5.1.tgz","integrity":"sha512-rUOU2IEgT77Y8OpSaGr7ZhkLbtvnCV9e6eAqKCxMEknmWwWDEvRdu8P7sjil8G/vs/Twyxw6uatGEJ5jaafiBg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNsIO/zq/d7kWEjKSFyl18/uuc0ao2a82kB0x793tEIgIgCXoXxnmkzlumq+oriyIuPKGM40tUr/f/GcJK1o7S8Rs="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.6.0":{"name":"controller","version":"0.6.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.4.4","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.6.0","dist":{"shasum":"b83257b4557aeb1427529b9da5be05580dcd022b","tarball":"https://registry.npmjs.org/controller/-/controller-0.6.0.tgz","integrity":"sha512-DoUrTsLVH1ZXJ4IVVy2j+qP5mfPR0ViYkYlB6MitybyDm7RywUgAkJ41TqqOAv9K2yhvUkVAT0n+1wZeyyq+Gg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCWYQtrIu9eZh7hLHLFXEU92hrnNW6A7HzN3bF6QnJG0AIgJZ94r/ZLqr3KMpyfMbg4ptTHS/gvELIOrtY+iVq7Uhc="}]},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.6.1":{"name":"controller","version":"0.6.1","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.4.4","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.6.1","dist":{"shasum":"b7cd45ba9703ecea62f7a2bcbb13cffdc503fdf6","tarball":"https://registry.npmjs.org/controller/-/controller-0.6.1.tgz","integrity":"sha512-S3zmKjUC5MhPq0IlsxjD9EtlvhPkEAMRk+s+iA/uDwrsP+PCbAjYIKDX/8IxGsld0c/fycPbpU7V/k7DHu+Zpw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGUnJxZpZoNL0q6m1sBh1NSnvQbg0ZNvOMWMIR+5SxwqAiEAk7FZXfFmpILTUpnZK/RzPWu6Dv2lT0ZK/Rf/X6gfjCY="}]},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"0.6.2":{"name":"controller","version":"0.6.2","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"supertest":"~0.1.2","mocha":"*"},"dependencies":{"express":"~3.4.4","underscore":"~1.3.3","methods":"0.0.1"},"_id":"controller@0.6.2","dist":{"shasum":"9fda8fc9d27dda80225953fd210dc7cfa5a9534e","tarball":"https://registry.npmjs.org/controller/-/controller-0.6.2.tgz","integrity":"sha512-KyRf1oHnL3+zrnDXq1p7DK+4OyrV5jJEVxnMwm4DGEZRv709NQzfY3DkeNxuYU64YqoXDHV/5jutxn6+o6o8Og==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCeMBed8+7bXFYX9WWlPLob3Z8ZxBqqleGIbB0bA5jCVgIgV7AoQh2/XJtA1E95oMzIwfIz+mdkzcdadwNQe8UDPX8="}]},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}]},"1.0.0":{"name":"controller","version":"1.0.0","description":"an action controller for express","main":"lib/controller.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec"},"license":"BSD","devDependencies":{"express":"^4.16.2","mocha":"^4.0.1","supertest":"^3.0.0"},"dependencies":{"cuid":"^1.3.8","methods":"^1.1.2","parseurl":"^1.3.2","router":"^1.3.2","underscore":"^1.8.3"},"gitHead":"c5be3412c25c53fc1271eed91defa34b106832a1","_id":"controller@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.0.0","_npmUser":{"name":"jonpacker","email":"contact@jonpacker.com"},"dist":{"integrity":"sha512-9tQ+JH8LgeN0PJYGuVCA21eLmty4+DOmfi2qJa4+2H+fcI35Y2QypaT4c/xKpQvBw7C/dV7zn3AAl2lTzy1e7Q==","shasum":"9efa6e6230e88d099a55a41a74d4d2338186817d","tarball":"https://registry.npmjs.org/controller/-/controller-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDvUTSRh9i+ru1aczfeurSB7mYwPunnbtvozspRBEq5OgIhAP9F9R9SVOaxoo/Jn1ZORmA6mdeDdFLV8X/6y5XAayBQ"}]},"maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/controller-1.0.0.tgz_1510330004464_0.234602942597121"}}},"readme":"# controller\na structural aid for creating express routes.\n\n## example\n\nThis code sets up an app with 3 handlers, 4 routes, and some middleware which\napplies to different handler groups.\n\n```javascript\nvar express = require('express');\nvar controller = require('controller');\n\nvar app = express();\nvar users = controller();\n\n// Define handlers\nusers.define('secret-stuff', ['sensitive'], function(req, res) {});\nusers.define('edit-account', ['sensitive'], function(req, res) {});\nusers.define('view-account', function(req, res) {});\n\n// Define middleware for all 'sensitive' grouped handlers\nusers.middleware('sensitive', function(req, res, next) {});\n// Define middleware for all handlers on this controller\nusers.middleware(function(req, res, next) {});\n// Define middleware for 'view-account'\nusers.middleware('view-account', function(req, res, next) {})\n\n// Define routes\nusers.get('/secret-stuff/:id', 'secret-stuff');\nusers.put('/user/edit/:id', 'edit-account');\nusers.get('/user/:id', 'view-account');\nusers.get('/view-user/:id', 'view-account');\n\n// Attach to the app\napp.use(users);\n```\n\n## documentation\n\n* [Usage](#constructor)\n* [Middleware Groups](#groups)\n* [Middleware Ordering](#ordering)\n* [define](#define) - define handlers\n* [middleware](#middleware) - add middleware for handlers\n* [route](#route) - route handlers\n* [direct](#direct) - directly route a handler function\n* [Mounting controllers on controllers & middleware inheritance](#inheritance)\n\n---\n\n<a name=\"constructor\"/>\n### Usage\n\nCreate a new controller by requiring controller and calling it as a function,\nlike this:\n\n```javascript\nvar controller = require('controller');\nvar users = controller();\n```\n\nThen attach it to an instance of express, as if it were middleware:\n\n```javascript\nvar app = require('express')();\napp.use(users);\n\n// It also works to attach it with a route, which will prefix all of the routes \n// in the controller with that path.\n\napp.use('/users/', users);\n```\n\n---\n\n<a name=\"groups\"/>\n### Middleware Groups\n\nController introduces the idea of middleware groups. This allows to you specify\nnamed groups, and apply to middleware to every handler that is labelled with\nthis group. For example, you might have bunch of handlers that require you to \nbe logged in, and some middleware which checks authentication. You could add\nall of the handlers to the 'require-login' group, and then add your auth\nmiddleware to the 'reguire-login' group. This will now apply that middleware to\nevery handler in the group.\n\nIn action:\n```javascript\nvar stuff = controller();\n\n// define handlers with their groups\nstuff.define('sensitive-thing', ['require-login'], function(req,res){});\nstuff.define('secret-thing', ['require-login'], function(req,res){});\n\n// define middleware for the group\nstuff.middleware('require-login', function(req, res, next) {\n  if (isAuthenticated(req)) {\n    next();\n  } else {\n    res.send(403);\n  }\n})\n```\n\n__Special Groups__\n\nThere are some special groups by default. The first one is `all`, which applies\nmiddleware to every action on this controller. Apart from that, every action\nname is also a middleware group, so you can add middleware to individual actions\n\n<a name=\"ordering\"/>\n__Middleware Ordering__\n\nMiddlewares are called in the following order:\n\n1. `'all'` grouped middleware is executed first. (in the order they were added)\n2. all other groups are then executed in the order they were added to the route\n   with `route` or `direct`. within the group, middlewares are executed in the\n   order they were added.\n3. route specific middleware (including middleware added inline on a `define`\n   call) is then executed in the order it was added.\n\nFor example:\n\n```javascript\napp.define('action', ['thing', MIDDLEWARE_1], routestr('str')); // inline middleware\napp.use('thing', MIDDLEWARE_2); // group middleware\napp.use('thing', MIDDLEWARE_3); // group middleware\napp.use(MIDDLEWARE_4); // global middleware\napp.use(MIDDLEWARE_5); // global middleware\napp.use('action', MIDDLEWARE_6); // route specific middleware\napp.use('action', MIDDLEWARE_7); // route specific middleware\napp.route('get', '/action', 'action');\n```\n\nThe call order of middleware in this example would be:\n\n```\n1. MIDDLEWARE_4 (global middleware)\n2. MIDDLEWARE_5 (global middleware)\n3. MIDDLEWARE_2 (group middleware)\n4. MIDDLEWARE_3 (group middleware)\n5. MIDDLEWARE_1 (route-specific middleware)\n6. MIDDLEWARE_6 (route-specific middleware)\n7. MIDDLEWARE_7 (route-specific middleware)\n```\n\n__Special ordering conditions__\n\n* Route names can be group names too. In the previous example, if I was to specify\n  `'action'` as the group for another route, the middleware added for `'action'`—\n  both inline and procedurally—will be called with group precedence, not route-\n  specific precedence. Route-specific precedence only applies to the middleware\n  added specifically for the current route.\n\n<a name=\"define\"/>\n### define(name, [groups], handler)\n\nDefine a handler. A handler is a function that is called as the result of a\nroute being visited. This does not route the handler, it only creates it, ready\nfor routing. \n\n__Parameters__\n* `name` - the name of the handler\n* `middleware/groups` *(optional)* - an array of middleware or groups to add this\n  handler to. Array can contain either strings (middleware group) or functions\n  (inline route-specific middleware) or a mixture of the two. For more details\n  on the order in which these middlewares are called, see the [ordering](#ordering)\n  section.\n* `handler` - the function that is called when the route is visited.\n\n__Example__\n\n```javascript\nusers.define('view', function(req, res) {\n  res.send(Users.read(req.params.id));\n});\n\nusers.define('edit', ['require-login'], function(req, res) {\n  Users.update(req.params.id, req.body);\n  res.send(200);\n});\n```\n\n---\n\n<a name=\"middleware\"/>\n### middleware(group\\*, middleware\\*)\n\nDefine some middleware(s) for a group(s). More than one middleware can be\npassed, as well as more than one group. If you were to pass two groups and two\nmiddlewares, each middleware would be added to both groups.\n\n`group` has some special values. `'all'` indicates that the middleware should\napply to every route on this controller. If you pass the name of an action as\nthe group, the middleware will apply to that action only.\n\n__Paramaters__\n* `group` - defaults to `'all'`\n* `middleware` - middleware to add to `group`.\n\n__Example__\n\n```javascript\nusers.middleware('auth', function checkAuthd(req, res, next) {\n  // check some auth\n});\n\n// Define some middleware for all routes\nusers.middleware(function(res, req, next) {});\n\n// Define some middleware for the 'getUser' action\nusers.middleware('getUser', function(req, res, next) {});\n```\n\n---\n\n<a name=\"route\"/>\n### route(method, path, handlerName)\n\nRoute a handler. Handlers can be routed at more than one location. Just like\nexpress, you can also use this method directly on the controller (see example).\n\n__Parameters__\n* `method`. The http method, for example `'get'`, `'post'`, `'put'`, etc.\n* `path`. The path to route the handler to, in exactly the same format you would\n  pass to express. You can use a regex, but it will ignore `options.prefix`.\n* `handlerName`. The name of the handler to route.\n\n__Example__\n```javascript\nusers.route('get', '/user/:id', 'view');\nusers.route('post', '/user/:id', 'create');\nusers.route('put', '/user/:id', 'edit');\n\n// or directly on the controller\nusers.get('/user/:id', 'view')\nusers.post('/user/:id', 'create');\nusers.delete('/user/:id', 'delete');\n```\n\n---\n\n<a name=\"direct\"/>\n### direct(method, path, [middleware\\*/groups\\*,] handlerfn)\n\nDirectly route a function optionally with some middleware. This is essentially\nthe same as adding a route directly to express. The difference is that handlers\ndefined with `direct` can be included in the controller's middleware groups, and\nwill be included in the `all` group. \n\n__Paramaters__\n* `method`. The http method, for example `'get'`, `'post'`, `'put'`, etc.\n* `path`. The path to route the handler to, in exactly the same format you would\n  pass to express. You can use a regex, but it will ignore `options.prefix`.\n* `middleware/groups`. A bunch of middlewares or groups to add the route to.\n  These can be mixed and matched, Controller will figure it out.\n* `handlerfn`. The handler function to call when the route is visited.\n\n__Example__\n```javascript\nvar uselessMiddleware = function(req,res,next) { next(); };\n\nusers.direct('delete', '/user/:id', uselessMiddleware, 'require-login', function(req, res) {\n  Users.delete(req.params.id);\n  res.end();\n});\n\nusers.direct('get', '/user/do-something', function(req, res) {});\n```\n\n---\n\n<a name=\"inheritance\"/>\n### Mounting controllers on controllers & middleware inheritance\n\nYou can mount a controller on another controller like so:\n\n```javascript\nvar appController = Controller();\nvar usersController = Controller();\n\nappController.use('/users', usersController);\n```\n\nThe path (in this case, `'/users'`) is optional, but it usually makes senses.\n\nMounting controllers on each other in this way will cause middleware inheritance.\nIn our above example, this means that `usersController` will inherit groups and\nmiddlewares from `appController`. If I set a global middleware on `appController`,\n`usersController` will get it too. This means that, for example, if I have a\ngroup `'auth'` on `appController`, I can use it as normal on `usersController`:\n\n```javascript\nusersController.define('editUser', ['auth'], function(req, res) { ... });\nappController.middleware('auth', function(req, res, next) { ... });\n```\n\n##### Middleware ordering when using inheritance\n\nThe run order of middleware is slightly different when utilising inheritance.\nNormally, the global middleware runs first, then the middleware in the order \nspecified on `define`. When utilising inheritance, this is still true, but within\na group, the lowest level of inheritance will run first.\n\nThe easiest way to demonstrate this is to show an example. Lets say we have 3\ncontrollers inheriting from each other, such as this:\n\n```javascript\nusersController.use('/cats', catController);\nappController.use('/users', usersController);\n```\n\nNow, lets say that each of these 3 controllers have one global middleware:\n\n```javascript\nappController.middleware(function(req, res, next) { console.log('app'); next() });\nusersController.middleware(function(req, res, next) { console.log('users'); next() });\ncatController.middleware(function(req, res, next) { console.log('meow'); next() });\n```\n\nLets also say that each of these 3 controllers have one middleware in a group\ncalled `'auth'`.\n\n```javascript\nappController.middleware('auth', function(req, res, next) { console.log('app (auth)'); next() });\nusersController.middleware('auth', function(req, res, next) { console.log('users (auth)'); next() });\ncatController.middleware('auth', function(req, res, next) { console.log('meow (auth)'); next() });\n```\n\nAnd we have a route which consumes these middlewares:\n\n```javascript\ncatController.direct('get', '/meow', ['auth'], function(req, res) {\n  res.end('MEOW');\n});\n```\n\nWhen we send a request to `/users/cats/meow`, the output would be as follows:\n\n```\napp\nusers\nmeow\napp (auth)\nusers (auth)\nmeow (auth)\n```\n\nSo the middleware group order was:\n\n```\nappController [global]\nusersController [global]\nmeowController [global]\nappController [auth]\nusersController [auth]\nmeowController [auth]\n```\n\nThe ordering in which lower levels of middleware are called will not change,\nregardless of the order they are added in.\n","maintainers":[{"name":"jonpacker","email":"contact@jonpacker.com"}],"time":{"modified":"2022-06-13T22:45:12.395Z","created":"2012-08-02T08:33:53.789Z","0.1.0":"2012-08-02T08:33:55.513Z","0.2.0":"2012-08-03T09:44:30.947Z","0.2.1":"2012-08-06T08:55:47.629Z","0.2.2":"2012-08-06T10:16:32.266Z","0.3.0":"2012-08-10T11:31:10.747Z","0.4.0":"2012-08-16T11:52:58.035Z","0.4.1":"2012-08-16T11:56:33.717Z","0.4.2":"2013-06-26T13:08:55.169Z","0.5.0":"2013-11-20T22:35:56.430Z","0.5.1":"2013-11-25T15:15:00.195Z","0.6.0":"2014-04-30T12:51:00.924Z","0.6.1":"2014-05-16T10:44:49.838Z","0.6.2":"2014-08-01T13:30:42.805Z","1.0.0":"2017-11-10T16:06:45.528Z"},"users":{"fgribreau":true},"license":"BSD","readmeFilename":"README.md"}