{"name":"middie","version":"3.2.1","description":"Middleware engine for Fastify","main":"middie.js","scripts":{"test":"standard && tap test.js","coverage":"tap --cov --coverage-report=html test.js"},"keywords":["fastify","middleware","webframework","performances"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"contributors":[{"name":"Tomas Della Vedova","url":"http://delved.org"}],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fastify/middleman.git"},"bugs":{"url":"https://github.com/fastify/middleman/issues"},"homepage":"https://github.com/fastify/middleman#readme","devDependencies":{"pre-commit":"^1.2.2","serve-static":"^1.12.4","standard":"^12.0.0","tap":"^12.0.0"},"dependencies":{"path-to-regexp":"^2.0.0","reusify":"^1.0.2"},"readme":"# middie\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/middie.svg)](https://greenkeeper.io/)\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/middie.svg?branch=master)](https://travis-ci.org/fastify/middie)\n\n*middie* is the module that add middlewares support on steroids to [Fastify](https://www.npmjs.com/package/fastify).\n\nThe syntax style is the same as [express](http://npm.im/express)/[connect](https://www.npmjs.com/package/connect).\nDoes not support the full syntax `middleware(err, req, res, next)`, because error handling is done inside Fastify.\n\nIf you want to see how use this module with Fastify, check [here](https://github.com/fastify/fastify/#fastifyusemiddlewarereq-res-next).\n\n## Install\n\n```\nnpm install middie --save\n```\n<a name=\"usage\"></a>\n## Usage\n```js\nconst Middie = require('middie')\nconst http = require('http')\nconst helmet = require('helmet')\nconst cors = require('cors')\n\nconst middie = Middie(_runMiddlewares)\nmiddie.use(helmet())\nmiddie.use(cors())\n\nhttp\n  .createServer(function handler (req, res) {\n    middie.run(req, res)\n  })\n  .listen(3000)\n\nfunction _runMiddlewares (err, req, res) {\n  if (err) {\n    console.log(err)\n    res.end(err)\n    return\n  }\n\n  // => routing function\n}\n```\n<a name=\"keep-context\"></a>\n#### Keep the context\nIf you need it you can also keep the context of the calling function by calling `run` with `run(req, res, this)`, in this way you can avoid closures allocation.\n\n```js\nhttp\n  .createServer(function handler (req, res) {\n    middie.run(req, res, { context: 'object' })\n  })\n  .listen(3000)\n\nfunction _runMiddlewares (err, req, res, ctx) {\n  if (err) {\n    console.log(err)\n    res.end(err)\n    return\n  }\n  console.log(ctx)\n}\n```\n\n<a name=\"restrict-usage\"></a>\n#### Restrict middleware execution to a certain path(s)\nIf you need to run a middleware only under certains path(s), just pass the path as first parameter to `use` and you are done!\n\n*Note that this does support routes with parameters, e.g. `/user/:id/comments`, but all the matched parameters will be discarded*\n\n```js\n// Single path\nmiddie.use('/public', staticFiles('/assets'))\n\n// Multiple middleware\nmiddie.use('/public', [cors(), staticFiles('/assets')])\n\n// Multiple paths\nmiddie.use(['/public', '/dist'], staticFiles('/assets'))\n\n// Multiple paths and multiple middleware\nmiddie.use(['/public', '/dist'], [cors(), staticFiles('/assets')])\n```\n\nTo guarantee compatibility with Express, adding a prefix uses [`path-to-regexp`](https://www.npmjs.com/package/path-to-regexp) to compute\na `RegExp`, which is then used to math every request: it is signficantly slower.\n\n## Acknowledgements\n\nThis project is kindly sponsored by:\n- [nearForm](http://nearform.com)\n- [LetzDoIt](http://www.letzdoitapp.com/)\n\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","readmeFilename":"README.md","gitHead":"206483049bad3b27521e8e704fd1e7fbe9e4c367","_id":"middie@3.2.1","_nodeVersion":"10.14.2","_npmVersion":"6.6.0","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"dist":{"integrity":"sha512-K4L4De0X4tqLOuxna4Y2Bg9U1p9k8ZRtJHp9i6yOT6b2rOmvP06MW9Yas2AzTQJAGkhC74VM8kOI+x0x41+77Q==","shasum":"90fde2e6bbcbc2c0b61082a09a7623aaa40cf1ff","tarball":"https://registry.npmjs.org/middie/-/middie-3.2.1.tgz","fileCount":6,"unpackedSize":17982,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcRZOqCRA9TVsSAnZWagAAyeYQAKOp1OsWYElr6PZUh8/p\nTP9lo/UpKMhJ/w+4D4yY/tj9xDyY6ZV1WQ8G8XsyoyKTbP50jBIjzmqIfHs5\n3UP3xIX0CvAYsxH4g1KcVSWu73OVSvyTdbzJ23NPmM3nLBcyJIJtd9r8KzYl\nNN+4HEuSP/OAjPyitQAxgQ/ZiMX98uvTuEkiPcm0zDqbnO16nCQZvTnD4afi\niaeYXVW4GI9eT465qbQfSf0pQkbkAFK5+uam4eq5MD7cOUnQgPf8SzmbyJWZ\nFwSkdQSUocjKZo8fx4t2hB6JSs7OQRwnoJCB+G1uawZH7navsw5j6EHD3iwS\nKhDBMz3rnbeVGSxcAoWuqDWkqrt8FLUKgvxcWSuJkIo6e6Y0A+oOWjnzz8uB\n838cyAtOyinJqgIy7nELytg548KA9NXErIs/RRJ5gYcYyUORbqUzVUK2635J\nzSmlLh8vpY6d62rC7iFcwzDMRv9TX7O4ip6FiZ9G/c48Dc3fizbWD4VIfIEU\n/T2wHaWUooE26CAXDwJpRRHfHM2Eh5hQJUGJQJKLT6No7fgvUdddg2iz7AG0\n/XZjFiQiZVqAY9ikpUJiICJhdfK/dkB0BlsEDCWezgeR39ZRrpAYEUQFyIf8\n6eDOiiVgH85elVFo3EOlSvGf4HuSSQb3WelzrcT1G1waBtlCoB/+KoFsLM+O\nPQ1q\r\n=VUmF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDQRABH1qUxYiCQPCmQ4lUDfEiqTh0NKdFyNjn7QH4l0AiEAqnUiLwwLk9PFbSF8sSZ9jvTU/GpqY0lbYhli1a22BB0="}]},"maintainers":[{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/middie_3.2.1_1548063658289_0.8134544952148859"},"_hasShrinkwrap":false}