Skip to content

Commit

Permalink
Upgrade to http-proxy-middleware v3
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Dec 16, 2024
1 parent 93a870e commit 283ce81
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
## Unreleased

### Changed

- Upgrade to http-proxy-middleware v3

## [[v1.0.0]](https://github.com/torchbox/storybook-django/releases/tag/v1.0.0) (2024-07-27)

### Added
Expand Down
187 changes: 87 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"nunjucks"
],
"dependencies": {
"http-proxy-middleware": "^2.0.0"
"http-proxy-middleware": "^3.0.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
Expand Down
13 changes: 1 addition & 12 deletions src/middleware.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
const { createProxyMiddleware } = require('http-proxy-middleware');

// https://github.com/chimurai/http-proxy-middleware/issues/40#issuecomment-249430255
const restream = (proxyReq, req) => {
if (req.body) {
const bodyData = JSON.stringify(req.body);
proxyReq.setHeader('Content-Type', 'application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
};

/**
* Initialises a http-proxy-middleware for Storybook to talk to Django without CORS issues.
* @param {object} options options
Expand All @@ -24,9 +14,8 @@ const createDjangoAPIMiddleware = (options) => {
router.use(
apiPath,
createProxy({
target: origin,
target: `${origin}${apiPath}`,
changeOrigin: true,
onProxyReq: restream,
}),
);
};
Expand Down

0 comments on commit 283ce81

Please sign in to comment.