-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
how to resolve CORS block in storybook ? #5
Comments
@shen-yu Thanks for opening the ticket! Looks like this can be solved by creating a custom Express.js application that serves Storybook as middleware - there's a helpful GitHub issue here documenting that process. Looks like you can do something like this to proxy requests through your Express.js app: var Express = require('express')
var proxy = require('http-proxy-middleware')
var storybook = require('@kadira/storybook/dist/server/middleware').default
var app = new Express()
var port = 4001
var storybookConfig = './.storybook'
app.use(storybook(storybookConfig))
app.use('/api', proxy({
target: 'https://api-endpoint', // target host
changeOrigin: true,
}))
app.listen(port, function (error) {
if (error) {
console.error(error)
} else {
console.info('==> Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port)
}
}) I haven't tested this solution myself, but let's leave this ticket open - if anybody else would like to see this available as a core feature in the |
I've found a good solution for this inside Storybook:
const { createProxyMiddleware } = require("http-proxy-middleware");
// Adds Storybook server middleware to proxy requests to /api to http://localhost:3030
// The `http://localhost:3030` target is where local plugins are served when using @codotype/cli
module.exports = function expressMiddleware(router) {
router.use(
"/api",
createProxyMiddleware({
target: "http://localhost:3030",
changeOrigin: true,
}),
);
}; If anyone wants to add this to the documentation in |
hello, i'm configure this to aviod CORS block, but it's not work, how can i do?
The text was updated successfully, but these errors were encountered: