0

We are trying MirageJS in our VueJS application and in a login screen, it makes a request post("auth/signin"). The api url is like http://localhost/v1 and it is configured in Axios instance as baseUrl. The MirageJS server routes has this.namespace="v1" (I tried /v1, /v1/, v1/), and this.post("/auth/signin", cb(schema, request)).

When I make the request I get this error enter image description here

Vue code

enter image description here

Where http is an instance of axios

enter image description here

What could it be?

enter image description here

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104
Gabriel Silva
  • 69
  • 1
  • 9
  • Hm, looks like your Vue app is making a request but just to `localhost` with no port specified. I'm guessing your Vue CLI dev server is serving on some port, say `localhost:3000`. Can you share the Vue code that is actually making the ajax request? – Sam Selikoff Mar 17 '20 at 14:50
  • 1
    (by default Mirage route handlers attach themselves to the current port, something like `localhost:3000`. You could try setting the `urlPrefix` to just `http://localhost` and see if that helps https://miragejs.com/api/classes/server/#url-prefix but I think your app code is the problem.) – Sam Selikoff Mar 17 '20 at 14:52
  • 1
    It's solved. I can't tell exactly why, but I used urlPrefix passing my api url with port and it did work now. Thank you. – Gabriel Silva Mar 17 '20 at 15:38
  • Next debugging step is to remove `namespace` and write out fully qualified domain name in the handler: `this.post('http://localhost/v1/auth', (schema, request) =>`. – Sam Selikoff Mar 17 '20 at 15:38

0 Answers0