1.1.0 • Published 5 years ago

modify-response-middleware v1.1.0

Weekly downloads
58
License
MIT
Repository
github
Last release
5 years ago

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