Skip to content

Commit f256739

Browse files
committed
update readme
1 parent f895111 commit f256739

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
# http-proxy-middleware-body
1+
# http-proxy-middleware-body
2+
3+
```javascript
4+
5+
// ...
6+
7+
const express = require('express'),
8+
{createProxyMiddleware} = require('http-proxy-middleware'),
9+
10+
app = express();
11+
12+
app.use(createProxyMiddleware(SOME_CONTEXT, {
13+
14+
// other configs...
15+
16+
onProxyRes: (proxyRes, req, res) => getBody(res, proxyRes, rawBody => {
17+
18+
if (!rawBody) {
19+
return;
20+
}
21+
22+
try {
23+
24+
// if it's a json body
25+
const body = JSON.parse(rawBody);
26+
27+
// token expired
28+
if (body.code === TOKEN_EXPIRED_CODE) {
29+
// remove token...
30+
}
31+
32+
} catch (e) {
33+
// do something...
34+
}
35+
36+
})
37+
38+
}));
39+
40+
// ...
41+
42+
```

0 commit comments

Comments
 (0)