BGTabulation BGTabulate
BGTabulation BGTabulate

Reputation: 1737

Ionic Capacitor Network error "at t.exports (http://localhost/js/chunk-vendors.6faaceee.js:7:66512)\n " using Android emulator

I'm using Ionic/Vue and simple axios post request to my server. It works well until I run it on android emulator using capacitor ionic capacitor copy android. But when I tried to login to the android emulator it gives me this error. Please help

2019-07-14 18:48:06.318 9746-9896/io.ionic.starter I/Capacitor/Plugin/Console: {"message":"Network Error","name":"Error","stack":"Error: Network Error\n at t.exports (http://localhost/js/chunk-vendors.6faaceee.js:7:66512)\n at XMLHttpRequest.l.onerror (http://localhost/js/chunk-vendors.6faaceee.js:43:11967)","config":{"url":"http://192.168.1.7:3333/api/auth/login","method":"post","data":"{\"username\":\"\",\"password\":\"\"}","headers":{"0":"application/json","Content-Type":"application/json;charset=utf-8","Access-Control-Allow-Origin":"*","Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"},"proxy":{"host":"http://192.168.1.7","port":"3333"},"baseURL":"http://192.168.1.7:3333/","transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1}}

Upvotes: 3

Views: 1206

Answers (1)

risingagain
risingagain

Reputation: 308

It's a CORS error. So you need to use proxy in your Vue app.

// vue.config.js
module.exports = {
  devServer: {
    proxy: 'http://YOUR_API_URL'
  }
}
// AND call 'http://localhost' for api call

Upvotes: 0

Related Questions