http-proxy-middleware-body
v1.0.0
Published
Get response body for http-proxy-middleware
Downloads
141
Readme
http-proxy-middleware-body
Get response body when using http-proxy-middleware
.
Example
An example with express
server.
const express = require('express'),
{createProxyMiddleware} = require('http-proxy-middleware'),
getBody = require('http-proxy-middleware-body'),
app = express();
app.use(createProxyMiddleware('SOME_CONTEXT', {
// other configs...
onProxyRes: (proxyRes, req, res) => getBody(res, proxyRes, rawBody => {
if (!rawBody) {
return;
}
try {
// if it's a json body
const body = JSON.parse(rawBody);
// token expired
if (body.code === 'TOKEN_EXPIRED_CODE') {
// remove token...
}
} catch (e) {
// do something...
}
})
}));