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.

serveSinglePageApp can not use with query strings

See original GitHub issue

I have a website in Angular and it is published using workers KV. With version 0.0.7 I use serveSinglePageApp. It works when the url is like mysite.com/buy/item

but if the url is like mysite.com/buy/item?id=1234 it get an “could not find buy/item/index.html in your content namespace”

I know that the best design should be buy/item/1234 but i can not manage that because I need to manage externals responses to my site so I can not change that way.

Is any way to solve this?

Thanks in advance! Sebastián

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
sgiacosacommented, Jan 10, 2020

Hello, I got the solution. The problem is in the function

function serveSinglePageApp(request) {
  // First apply the default handler, which already has logic to detect
  // paths that should map to HTML files.
  request = mapRequestToAsset(request)

  // Detect if the default handler decided to map to
  // a HTML file in some specific directory.
  if (request.url.endsWith('.html')) {
    // If expected HTML file was missing, just return the root index.html
    return new Request(`${new URL(request.url).origin}/index.html`, request)
  } else {
    // The default handler decided this is not an HTML page. It's probably
    // an image, CSS, or JS file. Leave it as-is.
    return request
  }
}

I changed to

function serveSinglePageApp(request) {
  // First apply the default handler, which already has logic to detect
  // paths that should map to HTML files.
  request = mapRequestToAsset(request)

    const parsedUrl = new URL(request.url)
    
  // Detect if the default handler decided to map to
  // a HTML file in some specific directory.
  if (parsedUrl.pathname.endsWith('.html')) {
    // If expected HTML file was missing, just return the root index.html
    return new Request(`${new URL(request.url).origin}/index.html`, request)
  } else {
    // The default handler decided this is not an HTML page. It's probably
    // an image, CSS, or JS file. Leave it as-is.
    return request
  }
}
0reactions
aburycommented, Jul 15, 2020

@signalnerve Yeah i had to jump in and bump up the version of kv-asset-handler manually, but once I did that it was all good 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloudflare with "always use https" on breaks url and removes ...
I ran into this problem of Cloudflare dropping query strings and got around it by not using the Always uses https option. Instead...
Read more >
Passing Information via Query Strings - Qualtrics
A query string allows you to pass information to and from a website by simply adding, or “appending,” that information to the end...
Read more >
Caching content based on query string parameters
Some web applications use query strings to send information to the origin. ... If you don't forward query strings, CloudFront doesn't cache based...
Read more >
What Are Query Strings & Parameters - How to Optimize
a query on using query parameters title graphic. A website isn't a static brochure — or at least it shouldn't be. Your site...
Read more >
Query string query | Elasticsearch Guide [8.5] | Elastic
Because the query syntax does not use whitespace as an operator, new york city is passed as-is to the analyzer.
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