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

Add support for connect-history-api-fallback? #457

Closed
douglasback opened this issue Mar 30, 2017 · 4 comments
Closed

Add support for connect-history-api-fallback? #457

douglasback opened this issue Mar 30, 2017 · 4 comments

Comments

@douglasback
Copy link
Contributor

Versions of kyt, node, OS

Latest!

Bug or Feature?

Feature! (Request? But also I can have a PR for this as I've done half of the work on a fork.)

Current Behavior

I started a static client-side only project created based on the kyt-starter-static starter kyt.

I'm relying on React Router for any and all navigation. Currently, when working locally (npm run dev) if I navigate to a page other than the root (i.e. from http://localhost:3001/ to http://localhost:3001/something), reloading the page gets a 404 as the express server can't find assets to serve from /something.

Desired Behavior

Ideally, refreshing the page on a route doesn't 404! If the Connect server started by kyt's dev action took advantage of a history api fallback middleware, this wouldn't happen.

This could take a couple of different forms, but the simplest one is to extend add a second line to this making it look like:

if (!hasServer) {
  app.use(history(historyMiddlewareOptions));
  app.use(express.static(publicSrcPath));
}

The middleware can also accept a variety of options; allowing those to be defined in the kyt.config.js would make them accessible here.

As I mentioned, I've done half of the work here in a fork and would be happy to contribute a PR. But also if this is possible today without making changes, then let me know!

@delambo
Copy link
Member

delambo commented Mar 30, 2017

Hey, Douglas - it's great to see you around here! Sorry you ran into this problem; it's not documented well. I figured folks would setup nginx or build a simple one-page/route-less app.

That said, I think this might be a good change for dev. What do you plan on doing with your production build? Would you run nginx in front of your app and route everything to the root html file?

@douglasback
Copy link
Contributor Author

Ah yes, important context here — the use case for production is that the app is served from an S3 bucket, which is fronted by Varnish (any CDN would probably do here). Varnish's configuration would serve the root HTML file from any path, allowing the Router to determine which components to render.

@delambo
Copy link
Member

delambo commented Mar 31, 2017

Ah, cool. I think this would be a good addition to dev. Push up on your fork when you get a chance. As a followup we should add some docs about this magic and a note about how to prepare for production.

@delambo
Copy link
Member

delambo commented Apr 11, 2017

this made it out in 0.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants