-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
src/middleware: open router handler for developers. #435
Conversation
879d247
to
6469f0f
Compare
I wanna know why you need this. |
I think there are many valid use cases for this and users and addon developers can do many awesome things using this feature. But this feature comes with a huge cost. At the moment, storybooks can be built as static webpages. This enables users to deploy them to GIthub pages, etc. (I have a few more features planned which also depend on being able to deploy as static web apps). But let's keep this issue open so we can discuss it more and get more opinion |
I don't like to allow to configure Storybook in the server side. This will open to a lot of issues we never want to address. |
First, i'm so sorry. My engilish is very bad. I am developing an in-house development tool based on storybook. I want to be able to dynamically generate some files in the server, through the HTTP to the client. For example, compiled a So, open middleware to me is the most rapid solution. Doesn't seem to cause too much of a problem. |
Another use case (my own) is proxy for API calls. Storybook is just as good tool that you can never find all ways to use it! And I use it to test parts of my app talking with not-really-cors-friendly API so I need a proxy. I wouldn't like to continue working on |
|
Hi @bshy522 @erykpiast @ndelangen Here's an example module.exports = function (router) {
router.get('/hello', (req, res) => {
res.send('Hello World!');
res.end();
});
} With this feature, we can also bring back the local-db: |
It took me a few hours to find this and know that I needed to call the file Thank you for making it so flexible though. It's now that I understand how to manipulate Express/Storybook. |
hey, @interactivellama! |
I just needed a url alias to align with our internal react project with the Salesforce Lightning Design System. The following simple middleware worked for me.
My primary issue was that until I found this issue I knew how to do it in express, but not how to connect it to Storybook. I looked through the source code for a while and knew it could be done. So my request was just to say, "hey if you want Express middleware, then put it in a file called middleware.js in the config folder." |
This feature needs proper documentation 😄 |
add the following "middleware.js" file to your .storybook folder:
obviously you can config it as you like. |
Was this feature ever documented anywhere? It's really useful, but I had to go digging through a bunch of issues to find it. |
Also it would be great to have typescript support for middleware 👍 |
For people having trouble using |
In my case I need to create a websocket connection and I think I would need access to the whole express app instead. Anyone has any ideas how can this be achieved? |
Would it be possible for us to access the environment variables at this point (within the middleware definition)? |
@thani-sh solution worked for me with storybook v6.3.8, angular v12 in development mode using start-storybook. But when I build the storybook using build-storybook, middleware is not getting included in the static build folder. Can someone help me with this? |
middleware cannot be included in the static build due to the static(HTML, CSS, js) nature of the latter. |
@theKashey or @Ananya-96 are you aware of a work around? P.S. I ve also tried msw-storybook-addon but i dont seem to be able to make it work (not sure if its from my implementation or it just doesnt work with angular and nx). Any help / direction would be appreciated thanks a lot |
This commit allows the developers to customize the middleware.