Wednesday 24 May 2017

Ionic 2 application doesn't start on device

I am trying to test my application written in Ionic 2 framework on actual device. The problem is that whenever I try to call my node.js API from device, the call does not even get there. Everything works fine on computer with ionic server command, but I cannot run it on my phone when I use ionic cordova run android. I can run sample applications that do not use my API with no errors.

My API code that allows any origin is following:

app.all('/*', function(req, res, next) { 
   var origin = req.headers.origin;

   res.setHeader('Access-Control-Allow-Origin', origin);
   res.header("Access-Control-Allow-Credentials", "true");
   res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
   res.header("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
   next();
});

And my code on client side that calls API is:

  checkLogin(): Observable<boolean>{
     return this.http
    .get(`http://localhost:8080/user/loginstatus`, { headers: this.getHeaders(), withCredentials: true})
    .map((res: Response) => {
   if(res.json()==true){
     return true;
   }
   else{
     return false;
   }
  });
 }

Basicly I would like to check if user is logged in so I can set the proper root page in the beggining of the app start. Please help. Thank you in beforehand.



via Luki

No comments:

Post a Comment