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.

urlPrefix and passthrough() are not working together

See original GitHub issue

Issue type: Bug

Current Behavior: I have set up my server as below:

  const server = new Server({

    routes() {
      this.urlPrefix = 'api';

      this.get('users', () => {
        return [];
      });

      this.get('meta-data', () => {
        return {};
      });

      this.passthrough();
    }

  });

The issue is I have another library for internationalization which makes a request for a static JSON file that contains the translation data. If I set a urlPrefix or namespace property of the server, it throws the error as miragejs tries to intercept that request.

Expected Behavior: If I add the method this.passthrough() in the routes() it should not throw an error and miragejs should allow that request to pass through.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
samselikoffcommented, Aug 17, 2020

This is a sort of confusing part of the routes API but if you specify urlPrefix or namespace it applies to every route definition that follows it, and also affects calls to this.passthrough().

All you need to do is reset it before calling passthrough() and all current origin requests should start passing through:

https://miragejs.com/repl/v1/311

0reactions
vnabetcommented, Nov 7, 2022

It’s really weird. I have the same problem with transloco (Angular internationalization lib)

the i18n json files are not in the same configured prefixUrl and namespace but Mirage throw an error

Mirage: Your app tried to GET './assets/i18n/fr-FR.json?v=166783724', 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? The existing namespace is undefined

By the way, @samselikoff your solution works … but really i don’t understand why Mirage catch these routes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passthrough for assets works only first time on page load #486
Hello, I setup passthrough for assets like this: export function ... I'm not entirely positive if our Angular integration is working yet, ...
Read more >
Server - Mirage JS
You can pass a function to passthrough to do a runtime check on whether or not the request should be handled by Mirage....
Read more >
vue.js - Mirage undefined error (no route defined) when ...
My problem was that my API is running on a different port than my ... By default this.passthrough() only works for requests on...
Read more >
Configuration - Motion
Version 4.2 Version 4.3 Version 4.4 Current Ve... mmalcam_control_params mmalcam_control_params mmalcam_params mmalcam... ffmpeg_duplicate_frames ffmpeg_duplicate_frames movie_duplicate_frames movie_du... netcam_high_params netcam_hi...
Read more >
Stream | Node.js v19.3.0 Documentation
However, if calling write() is preferred, it is possible to respect backpressure and avoid memory issues using the 'drain' event: function write(data, cb)...
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