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.

Passthrough for assets works only first time on page load

See original GitHub issue

Hello,

I setup passthrough for assets like this:

export function startMockServer({ environment = 'test' }) {
  return new Server({
    environment,
    urlPrefix: 'http://localhost:3000',
    namespace: 'api',
    routes() {
      this.passthrough('http://localhost:4200/assets/**');

      this.get('config', () => {
        return { content: {} };
      });
    },
  });
}

when I open http://localhost:4200 for the first time, I see all assets are loaded and Mirage reports passthrough for them as expected but if I refresh the page, Mirage shows errors that it can’t load any of the assets:

Error retrieving icon: Mirage: Your app tried to GET 'assets/icons/menu.svg', but there was no route defined to handle this request. Define a route for this endpoint in your routes() config. Did you forget to define a namespace?

I tried to move passthrough below mock endpoints, also moving urlPrefix and namespace inside routes and configuring them after passthrough route but got same result.

Am I configuring Mirage in a wrong way or there is an issue ?

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
m0t0rcommented, May 27, 2020

After quite a bit of debugging I still wasn’t able to figure out why that issue happens in my project but fortunately I found out that you can pass a function to passthrough and solved it for me and now it works as expected every time:

this.passthrough(request => request.url.includes('assets'));
0reactions
m0t0rcommented, May 26, 2020

@samselikoff thanks for you reply. Unfortunately, I can’t reproduce this issue when I setup a small project, even though, I did all steps that are in my actual project and everything works as expected every time. My actual project is private, unfortunately I can’t share it. Do you have some tips/ideas what could possibly change behavior of Mirage ? Yes, I use latest 0.1.40 version. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make loader only run when page assets load the first ...
Try this solution,this worked for me, $(document).ready(function(){ var check=getCookie("loader"); if (check!="false") { var loader="true"; } ...
Read more >
Strategies for service worker caching - Chrome Developers
Let's start with a simple caching strategy we'll call "Cache Only". It's just that: when the service worker is in control of the...
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
The first time a user loads your app (i.e., visits your website), they don't have any JavaScript loaded. That means no React and...
Read more >
Button UI Not Working with The new Input system - Unity Forum
I am working on my first serious 2d afterwork unity project. ... Now I just load one scene at a time (no in-game...
Read more >
How To Use Preload and Prefetch in HTML to Load Assets
By setting the rel attribute to stylesheet in onload , the browser is told to use the resource. Since it's been already downloaded...
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