Search code examples
javascriptreactjsmockservermiragejs

How make request to MirajeJS js only when I need it


I have a fake server created with mirajeJs. All my requests are trying to contact him, how can I make a request for mirajeJs only in cases when I need it while making the rest of the requests to the real server


Solution

  • You can use a passthrough:

    createServer({
      routes() {
        // Allow unhandled requests on the current domain to pass through
        this.passthrough()
      },
    })
    

    See MirageJS Passthrough documentation.