Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy config compatibility with Create React App #2921

Closed
chrbala opened this issue Feb 6, 2018 · 7 comments
Closed

Proxy config compatibility with Create React App #2921

chrbala opened this issue Feb 6, 2018 · 7 comments

Comments

@chrbala
Copy link

chrbala commented Feb 6, 2018

Issue details

The proxy feature in Create React App should be supported by default for feature parity. This is a follow-up to #208 (comment)

Steps to reproduce

The proxy config is stored in package.json and is passed along to Create React App. This config should be consumed in Storybook as well. This can be done with the following code in the userland middleware.js file:

const proxy = require('http-proxy-middleware');

const { proxy: proxyConfigs } = require('../package.json');

module.exports = router =>
  Object.keys(proxyConfigs).forEach(key =>
    router.use(key, proxy(proxyConfigs[key]))
  );

Please specify which version of Storybook and optionally any affected addons that you're running

@storybook/react ^3.2.14

Affected platforms

This is a feature request and affects all platforms

@swillis12
Copy link

@chrbala as a heads up this does not work when specifying the proxy from create-react-app docs as follows in the package.json:
"proxy": "http://localhost:8080"

@chrbala
Copy link
Author

chrbala commented Feb 20, 2018

Ah, you're right, that wouldn't work, and would likely be the most common case.

@swillis12
Copy link

This is extremely useful and I'll be using it in the mean time but it would be cool to find a way to support this "simple" config too ( only if CRA continues to support it too :) ). Thanks for providing this 👍

@chrbala
Copy link
Author

chrbala commented Feb 20, 2018

There should be a fairly straightforward mapping from the simple config to the complex one, but offhand I'm not sure what it would be. Please add a note to this thread if you figure it out!

@swillis12
Copy link

I think something like this will work:

const proxy = require('http-proxy-middleware');

const { proxy: proxyConfigs } = require('../package.json');

module.exports = router => {
    if(typeof proxyConfigs === 'string')
        router.use(proxy('/', { target: proxyConfigs }));
    else
        Object.keys(proxyConfigs).forEach( key => router.use(key, proxy(proxyConfigs[key])) );
}

@stale
Copy link

stale bot commented Mar 24, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Mar 24, 2018
@stale
Copy link

stale bot commented Apr 23, 2018

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants