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 not working for storybook #11551

Closed
bsdis opened this issue Jul 15, 2020 · 3 comments
Closed

proxy not working for storybook #11551

bsdis opened this issue Jul 15, 2020 · 3 comments

Comments

@bsdis
Copy link

bsdis commented Jul 15, 2020

To make storybook truly useful it is necessary to be able to interact with a backend storage. That seems to be not really possible. The closest description i have found is a 4 year old issue: #208 which seems to not work anymore.
I am quite amazed how it is possible that this is not a built in feature and i don't understand why there is not a bigger demand for that feature.
I have the following in my .storybook/middleware.js:

const { createProxyMiddleware } = require("http-proxy-middleware");

const apiProxy = createProxyMiddleware("/api", {
  target: "http://localhost:8000",
});

module.exports = apiProxy;

however when i run npm run storybook i get this warning:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'indexOf' of undefined
    at matchSingleStringPath (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/context-matcher.js:43:21)
    at Object.match (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/context-matcher.js:12:16)
    at HttpProxyMiddleware.shouldProxy (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:69:35)
    at HttpProxyMiddleware.<anonymous> (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:27:22)
    at Generator.next (<anonymous>)
    at /Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:4:12)
    at HttpProxyMiddleware.middleware (/Users/baba/projects/z-ui/frontend/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:26:47)
    at _default (/Users/baba/projects/z-ui/frontend/node_modules/@storybook/core/dist/server/dev-server.js:152:3)
    at buildDevStandalone (/Users/baba/projects/z-ui/frontend/node_modules/@storybook/core/dist/server/build-dev.js:343:38)
    at async buildDev (/Users/baba/projects/z-ui/frontend/node_modules/@storybook/core/dist/server/build-dev.js:415:3)
(node:31019) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

And the proxying is not working i.e. when trying to access .e.g.
stageResponse = await axios.post<StageRemote>("api/org/stage/create", {... via storybook, it tries to go directly to localhost:9009 where storybook is running instead of going to localhost:8000 which is where it should be proxied to.

Why is this not working, and what needs to be done to be able to proxy requests to the correct backend?

@ghost
Copy link

ghost commented Jul 20, 2020

@bsdis, i try solution from #208 (comment) with your import declaration and it works for me.

const { createProxyMiddleware } = require("http-proxy-middleware");

module.exports = function expressMiddleware (router) {
  router.use('/api', createProxyMiddleware({
    target: "http://localhost:8000",
    changeOrigin: true
  }))
}

@stale
Copy link

stale bot commented Aug 16, 2020

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 Aug 16, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

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 Sep 20, 2020
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

2 participants