Skip to content

Commit 283ce81

Browse files
committed
Upgrade to http-proxy-middleware v3
1 parent 93a870e commit 283ce81

File tree

4 files changed

+93
-113
lines changed

4 files changed

+93
-113
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
55
## Unreleased
66

7+
### Changed
8+
9+
- Upgrade to http-proxy-middleware v3
10+
711
## [[v1.0.0]](https://github.com/torchbox/storybook-django/releases/tag/v1.0.0) (2024-07-27)
812

913
### Added

package-lock.json

Lines changed: 87 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"nunjucks"
3434
],
3535
"dependencies": {
36-
"http-proxy-middleware": "^2.0.0"
36+
"http-proxy-middleware": "^3.0.0"
3737
},
3838
"peerDependencies": {
3939
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"

src/middleware.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
const { createProxyMiddleware } = require('http-proxy-middleware');
22

3-
// https://github.com/chimurai/http-proxy-middleware/issues/40#issuecomment-249430255
4-
const restream = (proxyReq, req) => {
5-
if (req.body) {
6-
const bodyData = JSON.stringify(req.body);
7-
proxyReq.setHeader('Content-Type', 'application/json');
8-
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
9-
proxyReq.write(bodyData);
10-
}
11-
};
12-
133
/**
144
* Initialises a http-proxy-middleware for Storybook to talk to Django without CORS issues.
155
* @param {object} options options
@@ -24,9 +14,8 @@ const createDjangoAPIMiddleware = (options) => {
2414
router.use(
2515
apiPath,
2616
createProxy({
27-
target: origin,
17+
target: `${origin}${apiPath}`,
2818
changeOrigin: true,
29-
onProxyReq: restream,
3019
}),
3120
);
3221
};

0 commit comments

Comments
 (0)