{"_id":"express-interceptor","_rev":"24-6f5f5a441123221c340bac7dda253d5c","name":"express-interceptor","description":"A tiny interceptor for Express responses","dist-tags":{"latest":"1.2.0"},"versions":{"0.1.0":{"name":"express-interceptor","version":"0.1.0","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --recursive examples"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"pinox101@gmail.com","url":"https://github.com/p1nox"}],"license":"MIT","devDependencies":{"morgan":"~1.5.1","express":"~4.12.2","jade":"~1.9.2","chai":"~2.1.1","supertest":"~0.15.0","mocha":"~2.1.0"},"dependencies":{"debug":"~2.1.2"},"_id":"express-interceptor@0.1.0","dist":{"shasum":"19fbf7420a438818ec2403a5ccd948ba8e61ebba","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-0.1.0.tgz","integrity":"sha512-WphR0kULF3MQDFXU3tIt5Lr3c/A7ThBjOnPNrWxSDfvoKVjrcWj2+biZAki8g7osc6KAJQRriQ/eYIVM/+FgPg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCiygYtcE0PrAhvJAfn1QqlVnx6OaOPXHB0o4xinyf1kgIhALXal1VcvEHYvBUEBlYXjQxtSYPOSMmIoUIzsMG6kOZS"}]},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"flockonus","email":"fabianosoriani@gmail.com"},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"}]},"1.0.0":{"name":"express-interceptor","version":"1.0.0","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --recursive tests"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"pinox101@gmail.com","url":"https://github.com/p1nox"}],"repository":{"type":"git","url":"https://github.com/axiomzen/express-interceptor"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"},"license":"MIT","devDependencies":{"morgan":"~1.5.1","express":"~4.12.2","jade":"~1.9.2","chai":"~2.1.1","supertest":"~0.15.0","mocha":"~2.1.0","cheerio":"~0.18.0"},"dependencies":{"debug":"~2.1.2"},"homepage":"https://github.com/axiomzen/express-interceptor","_id":"express-interceptor@1.0.0","dist":{"shasum":"12ccc7d1c704aa075f12c4dd777259c496e252f3","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-1.0.0.tgz","integrity":"sha512-PWAxrusM44vSRmmQSimzX1UyUHb80iGxhVRgkWXAbuXXScfZZmhHGhU8YZtWHVEqUsJxIMmuks/kCDvpzukypw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCICF9UI6OB5o+xNeiT+6G4rfmjsiQmheb/aRcabITo+wIhALf1dbYbByWCBxbK4BUjyfDkX5wbZ0BelEWnuCJRhRga"}]},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"flockonus","email":"fabianosoriani@gmail.com"},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"pinox101@gmail.com"}]},"1.0.1":{"name":"express-interceptor","version":"1.0.1","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --recursive tests"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"pinox101@gmail.com","url":"https://github.com/p1nox"}],"repository":{"type":"git","url":"https://github.com/axiomzen/express-interceptor"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"},"license":"MIT","devDependencies":{"chai":"^2.3.0","cheerio":"^0.19.0","express":"^4.12.4","jade":"^1.10.0","mocha":"^2.2.5","morgan":"^1.5.3","supertest":"^1.0.1"},"dependencies":{"debug":"^2.2.0"},"gitHead":"7fcef406fcad8c7086dffdfaeadc02206764c1d6","homepage":"https://github.com/axiomzen/express-interceptor","_id":"express-interceptor@1.0.1","_shasum":"5c336d4501718719a180b91112c29d8e71267275","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"flockonus","email":"fabianosoriani@gmail.com"},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"pinox101@gmail.com"}],"dist":{"shasum":"5c336d4501718719a180b91112c29d8e71267275","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-1.0.1.tgz","integrity":"sha512-1UZIfkrTlNv/9VC1jk4TMDtWvWdYqGTvkKePe3Lfi68pWg9u1IJANm7GrddlrjHeFUC83iIHFhzUk+ZO0YIlkQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD/YhKF40FIr3CltG3ItcmyCHrIyVRig4sRBjkvQX0PegIhAKBWocFhOBTbE12WAtiJlW+YLFa+U6Gqp85UVKuesefN"}]}},"1.1.0":{"name":"express-interceptor","version":"1.1.0","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --recursive tests"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"pinox101@gmail.com","url":"https://github.com/p1nox"}],"repository":{"type":"git","url":"https://github.com/axiomzen/express-interceptor"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"},"license":"MIT","devDependencies":{"cheerio":"^0.19.0","express":"^4.12.4","jade":"^1.10.0","magicpen-media":"1.5.0","messy":"6.5.0","mocha":"^2.2.5","unexpected":"9.2.1","unexpected-express":"7.3.0","unexpected-messy":"4.6.0"},"dependencies":{"debug":"^2.2.0"},"gitHead":"651330fb2d81bb90ef9c874336dfc8796b77125f","homepage":"https://github.com/axiomzen/express-interceptor","_id":"express-interceptor@1.1.0","_shasum":"2ac3faaccc67c2098f4c697e2cc807737de34ade","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"p1nox","email":"pinox101@gmail.com"},"dist":{"shasum":"2ac3faaccc67c2098f4c697e2cc807737de34ade","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-1.1.0.tgz","integrity":"sha512-NQjZpRlqhzKFC07lmsyS3EKOKOkzYwTH0QKiNK/R7VmvNW5aXqfOqdqg4Wrv1JWqj0rrFk48V1miJ96eC98cqQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC9Qln81LPWLzVC9+NaTG4vLmxbPO1vnXho4He7rIHB0AiEA3O3fWsmlFigit6qcymEh9/lASzrVA+b/p6r5bTMlnwM="}]},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"pinox101@gmail.com"}]},"1.1.1":{"name":"express-interceptor","version":"1.1.1","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --recursive tests"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack","hijackresponse"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"ipinoraul@gmail.com","url":"https://github.com/p1nox"}],"repository":{"type":"git","url":"https://github.com/axiomzen/express-interceptor"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"},"license":"MIT","devDependencies":{"cheerio":"^0.19.0","express":"^4.12.4","jade":"^1.10.0","magicpen-media":"1.5.0","messy":"6.5.0","mocha":"^2.2.5","unexpected":"9.2.1","unexpected-express":"7.3.0","unexpected-messy":"4.6.0"},"dependencies":{"debug":"^2.2.0"},"gitHead":"c7f08f1006b433d5ff48606dfcb19a6cb4186b34","homepage":"https://github.com/axiomzen/express-interceptor","_id":"express-interceptor@1.1.1","_shasum":"19b1978aad0e277aca3ad58c69ac530b140f2595","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"p1nox","email":"pinox101@gmail.com"},"dist":{"shasum":"19b1978aad0e277aca3ad58c69ac530b140f2595","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-1.1.1.tgz","integrity":"sha512-lBcUCjXQXCzuxzTg/vDF5YXlYkkMuWrfb9hjNctLEUcUoyxR6xrideV+8HmXxRjgb5isNrLZOtjAJHQYHatNHQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGOAFJ1yNqcpaPlRqX2phy91Tt4G+BpDTxohFqiFLNpHAiBcEpYq89m+3wbjmh+Oyeq44HfCqRPNIFCqXUwItqmJjg=="}]},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"pinox101@gmail.com"}]},"1.2.0":{"name":"express-interceptor","version":"1.2.0","description":"A tiny interceptor for Express responses","main":"index.js","directories":{"test":"test"},"scripts":{"test":"mocha"},"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack","hijackresponse"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"ipinoraul@gmail.com","url":"https://github.com/p1nox"}],"repository":{"type":"git","url":"git+https://github.com/axiomzen/express-interceptor.git"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"},"license":"MIT","devDependencies":{"cheerio":"^0.19.0","express":"^4.12.4","jade":"^1.10.0","mocha":"^2.2.5","unexpected":"9.5.0","unexpected-express":"7.7.0"},"dependencies":{"debug":"^2.2.0"},"gitHead":"8e4ade1ca7916299d04ae06713a613a595719cb4","homepage":"https://github.com/axiomzen/express-interceptor#readme","_id":"express-interceptor@1.2.0","_shasum":"33460a8e11dce7e5a022caf555d377e45ddb822a","_from":".","_npmVersion":"2.14.20","_nodeVersion":"4.4.0","_npmUser":{"name":"p1nox","email":"ipinoraul@gmail.com"},"dist":{"shasum":"33460a8e11dce7e5a022caf555d377e45ddb822a","tarball":"https://registry.npmjs.org/express-interceptor/-/express-interceptor-1.2.0.tgz","integrity":"sha512-fCbcJv8ZwabDg0M/3PmHUxfr/WKHGMpAicR9TfGdhANV4M1GBDSrBTenHIK3aegyRN5S6eDwlvyNFiLynnc19w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD8nRnn+Z0c6zR8kFhW6WGRLSSq61hmffNYSBsS+CJ5agIhANJcRZVqxAjzELqnqpaqRr4yEyUmUIjLRfcVegfiTuX3"}]},"maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"ipinoraul@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/express-interceptor-1.2.0.tgz_1459694062687_0.1222392707131803"}}},"readme":"# express-interceptor\n\n_A tiny Express response interceptor_\n\n[![NPM](https://nodei.co/npm/express-interceptor.png)](https://nodei.co/npm/express-interceptor/)\n\n[![Build Status](https://travis-ci.org/axiomzen/express-interceptor.svg)](https://travis-ci.org/axiomzen/express-interceptor) [![Dependencies](https://david-dm.org/axiomzen/express-interceptor.png)](https://david-dm.org/axiomzen/express-interceptor.png)\n<a href=\"https://zenhub.io\"><img src=\"https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png\" height=\"18px\"></a>\n\nExpress-interceptor allows you to define a previous step before sending a response. This allows you to do anything you want with the response, such as processing, transforming, replacing, or logging it. Express-interceptor allows you to avoid calling `next()` over and over. Further more, you can avoid managing nested scopes. Using a declarative API, it’s simple to use and maintain.\n\nSome use cases include:\n\n- Transpile custom elements into standard HTML elements.\n- Transform JSX or compile less files on the fly.\n- Store statistics about responses.\n- Set response headers based on tags in the response body.\n- Dynamically inject live-reload scripts to HTML.\n\n## Usage\n\nInstall the package\n\n\n    npm i --save express-interceptor\n\nDefine your interceptor\n\n```javascript\nvar express     = require('express');\nvar cheerio     = require('cheerio');\nvar interceptor = require('express-interceptor');\n\nvar app = express();\n\nvar finalParagraphInterceptor = interceptor(function(req, res){\n  return {\n    // Only HTML responses will be intercepted\n    isInterceptable: function(){\n      return /text\\/html/.test(res.get('Content-Type'));\n    },\n    // Appends a paragraph at the end of the response body\n    intercept: function(body, send) {\n      var $document = cheerio.load(body);\n      $document('body').append('<p>From interceptor!</p>');\n\n      send($document.html());\n    }\n  };\n})\n\n// Add the interceptor middleware\napp.use(finalParagraphInterceptor);\n\napp.use(express.static(__dirname + '/public/'));\n\napp.listen(3000);\n\n```\n\nYou're defining an interceptor that will be executed whenever the response contains html as Content-Type. If this is true, it will append a child at the end of the body. In other words, it will transform the response:\n\n```html\n<html>\n<head></head>\n<body>\n  <p>\"Hello world\"</p>\n</body>\n</html>\n```\n\nInto:\n\n```html\n<html>\n<head></head>\n<body>\n  <p>\"Hello world\"</p>\n  <p>From interceptor!</p>\n</body>\n</html>\n```\n\nSee [more examples](https://github.com/axiomzen/express-interceptor/tree/master/examples). Also, you can debug express-interceptor actions using [debug](https://github.com/visionmedia/debug) env variable `DEBUG=express-interceptor`.\n\n## API\n\n* `isInterceptable()` (required): is a predicate function where you define a condition whether or not to intercept a response. Returning `true` buffers the request, and proceeds calling `intercept()` as well as `afterSend()`. Typically, you want to check for this condition in the `res` object in the definition of the middleware.\n\n* `intercept(body, send)` (required): Parse the body as an encoded string. After processing the body, call `send(newBody)` with the content to be sent back to the client.\n\n* `afterSend(oldBody, newBody)`: This method will be called after sending the response to the client – after the `done()` callback in the `send()` method is executed. This method would typically be used to cache something, log stats, fire a job, among other things.\n\n## Who is using it?\n\n* [node-stylus-require](https://www.npmjs.com/package/node-stylus-require)\n* [express-html-minify](https://www.npmjs.com/package/express-html-minify)\n* [express-jare](https://www.npmjs.com/package/express-jare)\n* [hospitalrun-server-routes](https://www.npmjs.com/package/hospitalrun-server-routes)\n\n## Similar to\n\n- [express-hijackresponse](https://github.com/papandreou/express-hijackresponse)\nDifferent API, using callbacks with no top down structure, more obtrusive to HTTP internals.\n\n- [hijackresponse](https://github.com/gustavnikolaj/hijackresponse)\nAttempting to solve same problems than `express-hijackresponse`. Different API using pipes, recommended if you have problems with [streaming](https://github.com/axiomzen/express-interceptor/issues/15) or if you need more control over responses.\n\n- [tamper](https://github.com/fgnass/tamper)\nSimilar functionality but different internals and API.\n\n## Words of advice\n\nIf your `intercept` method make calls to a database, or needs to make expensive transformations to the original response, you should take in account the time that will add to the response. You should define your `isInterceptable` method carefully, checking the type of the response, or even the route that was fired by the request, also you may consider implementing a cache strategy to get faster responses.\n\nIf you face any issue, don't hesitate to submit it [here](https://github.com/axiomzen/express-interceptor/issues).\n\n## Contributing\n\nPlease check [CONTRIBUTING.md](CONTRIBUTING.md).\n\nThis project adheres to the [Open Code of Conduct](http://todogroup.org/opencodeofconduct/#express-interceptor/ipinoraul@gmail.com). By participating, you are expected to honor this code.\n\n## Author\n\n* [AxiomZen](https://www.axiomzen.co/).\n\n## Collaborators\n\n* [Fabiano Soriani](https://github.com/flockonus).\n* [Raul Pino](https://github.com/p1nox).\n\n## License\n\n  [MIT](LICENSE)\n","maintainers":[{"name":"flockonus","email":"fabianosoriani@gmail.com"},{"name":"p1nox","email":"ipinoraul@gmail.com"}],"time":{"modified":"2022-06-17T22:21:38.493Z","created":"2015-03-06T21:08:16.690Z","0.1.0":"2015-03-06T21:08:16.690Z","1.0.0":"2015-03-16T20:10:37.402Z","1.0.1":"2015-05-25T19:16:31.673Z","1.1.0":"2015-08-05T13:19:55.479Z","1.1.1":"2015-08-05T14:02:56.833Z","1.2.0":"2016-04-03T14:34:24.787Z"},"keywords":["express","expressjs","middleware","modify","response","hack","interceptor","hijack","hijackresponse"],"contributors":[{"name":"Fabiano P Soriani","email":"fabianosoriani@gmail.com","url":"https://github.com/flockonus"},{"name":"Raul Pino","email":"ipinoraul@gmail.com","url":"https://github.com/p1nox"}],"author":{"name":"AxiomZen","url":"https://axiomzen.co"},"license":"MIT","readmeFilename":"README.md","users":{"flockonus":true,"rankun203":true,"benjaminokeefe":true,"dburdese":true,"goliatone":true,"shakakira":true,"zeke":true,"tonillo":true},"homepage":"https://github.com/axiomzen/express-interceptor#readme","repository":{"type":"git","url":"git+https://github.com/axiomzen/express-interceptor.git"},"bugs":{"url":"https://github.com/axiomzen/express-interceptor/issues"}}