modify-response-middleware

1.1.0 • Public • Published

modify-response-middleware

Middleware that allows you to modify the response data.

Installation

npm i modify-response-middleware

Node.js

import express from 'express'
import modifyRes from 'modify-response-middleware'
 
const app = express()
 
app.use(modifyRes((content, req, res) => {
  if (content) {
    const data = JSON.parse(content.toString())
    data.age += 2
    return Buffer.from(JSON.stringify(data))
  }
}, {
  noCache: true, // set request header "cache-control: no-cache", avoiding 304 responses
}))
 
app.get((req, res) => {
  res.json({
    name: 'Tom',
    age: 18,
  })
})
 
app.listen(3000)

License

MIT

Dependents (1)

Package Sidebar

Install

npm i modify-response-middleware

Weekly Downloads

753

Version

1.1.0

License

MIT

Unpacked Size

6.02 kB

Total Files

6

Last publish

Collaborators

  • zuojiang