I have created an app in IONIC using Cuba rest js which is getting data from CUBA application hosted on web. My ts file is like this
import { Component } from '@angular/core';
import * as cuba from '@cuba-platform/rest';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
myApp:cuba.CubaApp;
loginResult:string;
constructor() {
this.loginResult = "Initialised";
}
ionViewWillEnter(){
const app = cuba.initializeApp({
name: 'myApp',
apiUrl: 'http://xxxxxx.cloudjiffy.net/app/rest/',
restClientId: 'xxxxxxxx',
restClientSecret: 'xxxxxx'
});
this.myApp = cuba.getApp('myApp');
}
login(){
this.myApp.login('xxxxxxx','xxxxxxxxx').then(value =>{
this.loginResult = "Succesful";
})
.catch(ss=>{
this.loginResult = ss;
})
}
}
Though the application run smoothly with cuba application on local host, but with cuba application on web, it gives a CORS error.
IONIC app running on browser
Access to fetch at ‘http://tmphed.cloudjiffy.net/app/rest/v2/oauth/token’ from origin ‘http://localhost:8100’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
IONIC App running on mobile
CubaRestError: Failed to Fetch
I have tried org.apache.catalina.filters.CorsFilter CORS filters in TOMCAT web.xml file in webapps folder but no avail. There are large number of posts on stackoverflow saying that Catalina CORS filter in not working on TOMCAT and tried the solutions mentioned in these posts but not successfull.
CUBA documentation says by default, all CORS requests to the REST API are allowed.
Please guide
regards