question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: custom proxy settings

See original GitHub issue

First of all, great work with react-story book! I love how I can now jump between different states of my components quickly, and work on the visual changes.

So I have a component that fetches data from an api, and plots it onto a chart. Although I can write a story and feed mocked data into the component, sometimes it’s helpful to render the “smart” version of the component and see it in real action. Problem is, I used to setup my own express server with webpackDevMiddleware, and then configure proxies so I can redirect api calls to another port. I couldn’t find a way to setup similar configuration when using react-storybook. I ended up with a hack by going into node_modules/.bin/start-storybook and put my proxy settings there.

I’m not sure if this is a use case the authors intended to support, but I think it’ll be really nice if I can use react-storybook as a playground for all sorts of components, whether they’re dumb or smart. To achieve that, we would need a way to support custom proxy settings.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:39 (12 by maintainers)

github_iconTop GitHub Comments

97reactions
indiesquidgecommented, Jun 7, 2017

@ndelangen, just when I saw your message I was able to find a solution to my problem using the awesome middleware customization roughly outlined in #435.

It is a very similar solution to @yianL’s solution above, only I am not creating my own Express server and instead leveraging Storybook’s router handler in the middleware.

I have the following in .storybook/middleware.js

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

module.exports = function expressMiddleware (router) {
  router.use('/api', proxy({
    target: 'https://api-endpoint.com',
    changeOrigin: true
  }))
}

This has a dependency on the http-proxy-middleware package.

It uses a proxy function to map a context (“/api”) to a target (“api-endpoint.com”). One thing to note is that the changeOrigin option must be explicitly set to true in order for the origin of the host header to be changed to the target URL. The proxy function can be used for any number of proxies.

Thank y’all so much for exposing the middleware custom config in Storybook, that is a very helpful feature indeed 💛

10reactions
japboycommented, Mar 11, 2018

It is cool if devServer.proxy would work just like webpack-dev-server. I’m using Storybook w/ Vue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Custom Proxy | Progress Telerik Test Studio for APIs
Configure Custom Proxy. You can configure custom proxy by opening: Windows Start Menu > Internet Options > Connections tab > LAN Settings >...
Read more >
Using a custom proxy | Postman Learning Center
Select your active network connection, select Advanced, and select the Proxies tab. Select Web Proxy (HTTP) and enter the proxy address and port....
Read more >
Configuring Proxy Settings - Trend Micro
On the System tab, select Proxy from the drop-down menu. Enable Custom proxy settings and specify the following: Type the proxy server address...
Read more >
How to Set Up a Proxy Server on Your PC, Mac, or Web Browser
Click Start and select Settings (the gear icon) from the Start menu. · Choose Network & Internet. · Click Proxy in the left...
Read more >
Use a proxy server in Windows - Microsoft Support
To set up a proxy server connection automatically · Select the Start button, then select Settings > Network & internet > Proxy. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found