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

Middleware should enforce trailing / or use <base href> #590

Closed
ericclemmons opened this issue Nov 1, 2016 · 7 comments
Closed

Middleware should enforce trailing / or use <base href> #590

ericclemmons opened this issue Nov 1, 2016 · 7 comments

Comments

@ericclemmons
Copy link
Contributor

Hi! Given:

const storybook = require("@kadira/storybook/dist/server/middleware").default;
app.use("/stories", storybook(".storybook"));

Navigating to /stories results in a 404 of manager.bundle.js because it's loaded at /static/manager.bundle.js instead of /stories/static/manager.bundle.js.

There are two solutions to this:

  • Add <base href="${req.path}/" /> or equivalent in the the HTML.
  • Enforce the trailing slash in the middleware.

I can submit a PR for either depending on your preference.

@arunoda
Copy link
Member

arunoda commented Nov 1, 2016

@mnmtanish could you co-ordinate this?

@thani-sh
Copy link
Contributor

thani-sh commented Nov 1, 2016

I'll check it out

@ndelangen
Copy link
Member

Hey @ericclemmons Sounds like enforcing a trailing slash will be easy to do! Want to make that PR?

I'm also interested in a PR describing how to inject storybook within an express app, as you're doing I believe ?

@ericclemmons
Copy link
Contributor Author

This is what I have in our code now:

import { Router as router } from "express";
import storybook from "@kadira/storybook/dist/server/middleware";


export default router()
  .use(
      // Redirect stories to stories/, due to relative URLs
    (req, res, next) => {
      if (req.originalUrl === "/stories") {
        return res.redirect("/stories/");
      }

      next();
    },
     storybook(".storybook")
   )
 ;

Our app has docs, tools, stories, etc. all available when in development. (We found that no one runs stories if it's a separate process/script. Plus, we need the API access.)

@ndelangen
Copy link
Member

@ericclemmons Do you think you could write a blogpost & a section in our documentation detailing this and why it's working out so well for you?

@stale
Copy link

stale bot commented Nov 14, 2017

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 60 days. Thanks!

@stale stale bot added the inactive label Nov 14, 2017
@stale
Copy link

stale bot commented Nov 29, 2017

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!

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

5 participants