question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routing Client Side/Packaging for Deployment

See original GitHub issue

Expected behavior

I’ve written some routes that are not behaving as expected. I initially started off with the create-choo-app scaffolding; however, that required turned out to only be a good idea for development. When it came to deployment, my dynamic routes were all broken when I tried to push up my dist folder to s3 (where I am going to eventually host my choo site). So rather than use the fancy bankai package, I thought I would use browserify to get everything working. Again, this caused all my routes to break. Am I missing something, or do you have to run something like budo or bankai in order to serve the page up? Here is basically what I am doing:

index.html:

<html>
  <head>
    <script src='bundle.js'> </script>
  </head>
  <body>
  </body>
</html>

index.js

var html = require('choo/html')
var choo = require('choo')

var app = choo()
app.route('/', placeholder)
app.route('/:user', placeholder)
app.route('/:user/:repo', placeholder)
app.route('/:user/settings', placeholder)
app.route('/404', placeholder)

function placeholder (state) {
  console.log(state.params)
  return html`<body>placeholder</body>`
}

app.mount('body')

browserify command:

browserify index.js -o bundle.js

When I run a simple http server like python -m simpleHttpServer 8000 my initial route comes up fine. But then if I attempt to type localhost:8000/homer into the address bar I get a 404 error.

I would expect that I should get “placeholder”.

I guess ultimately my question is how do I get everything nice and packaged in the browser so that I can manually type routes in the address bar and get the results I am anticipating? Thanks!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rook2pawncommented, Dec 19, 2021

There is an ongoing discussion over at https://github.com/http-party/http-server/issues/757#issuecomment-984590971

What I am looking for primarily is

  • something simple precisely like http-server
  • something canonical and precise for using choo
  • " What you need to do is redirect any static route to the route where your choo app lives." - this is fine but we need the precise set of rules.
  • I will probably work with @johannesloetzsch and @thornjad to see if we can use http-server a canonical means.
1reaction
lviviercommented, Jul 28, 2018

@AcidLeroy the python simpleHTTPServer knows to rewrite the route / -> /index.html. That’s why that route works. But it doesn’t know to rewrite /homer, doesn’t find a file called “homer”, so it responds with a 404. You need to use a server that you can configure to rewrite the routes you want to use with your choo app.

At my work we use Caddy with its built-in rewrite directive for this purpose. Any full-featured HTTP server (nginx, Apache, etc.) can accomplish this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How deployment services make client-side routing work
Recently I deployed a Single Page Application (SPA) to Vercel (formerly Zeit). I was surprised to find that my client-side routes worked, even...
Read more >
Issues · choojs/choo - GitHub
New feature: Async route support ... Running Router On a Specific Path with Hash Routing ... Routing Client Side/Packaging for Deployment.
Read more >
Using route-based deployment strategies | Building applications
Some strategies use Deployment objects to make changes that are seen by users of all routes that resolve to the application. Other advanced...
Read more >
disco lheb londonisse: Topics by Science.gov
VISIR (discoVerIng Safe and effIcient Routes) is an operational decision support system ... A SidePack Aerosol monitor was used both inside and outside...
Read more >
Client-Side Routing not working with Heroku - React Rails ...
I deployed my app to Heroku. When running locally, I client-side routing works, but when on the Heroku deployment, I get error 404...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found