1

I am working with Ionic 3 app. Backend for my app is Odoo v11. When connecting my mobile app with Odoo v11 using angular4-odoo-jsonrpc I have to face below error.

Failed to load http://127.0.0.1:8069/web/session/authenticate: Response to the preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

this is my Code:

import { OdooJsOnProvider } from '../../providers/odoo-js-on/odoo-js-on';
import { Component } from '@angular/core';
import { AlertController, IonicPage, Loading, LoadingController, NavController, NavParams } from 'ionic-angular';
import { UtilsProvider } from "../../providers/utils/utils";
import * as Ng6OdooRPCService from 'angular6-odoo-jsonrpc';
import { OdooRPCService } from 'angular4-odoo-jsonrpc'


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(
    public navCtrl: NavController,
    private odooRPC: OdooRPCService
  ) {
    this.odooRPC.init({
      odoo_server: "http://127.0.0.1:8069",
      http_auth: "admin:admin" // optional
    });
    this.odooRPC.login('odoo', 'admin', 'admin').then(res => {
      console.log('login success');
    }).catch(err => {
      console.log('login failed', err);
    })
  }

}
Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35
Nazeeh
  • 45
  • 1
  • 10

3 Answers3

0

Two approaches.

Allow your localhost and port (8100) access by managing CORS on your backend

OR

Set-up proxying https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

KieranDotCo
  • 467
  • 2
  • 16
0

You have to manage CORS from your backend. Read more about CORS here.

If you want to test your mobile app avoiding CORS add this Extension to Google Chrome. But use this type of Extensions only for testing.

Sudarshana Dayananda
  • 5,165
  • 2
  • 23
  • 45
  • i stop the CORS from Browser using this command google-chrome --disable-web-security but still same error – Nazeeh Sep 12 '18 at 08:22
0

allow CORS in your backend like this :

@http.route('/route/<id>', type='http', cors='*', csrf=False, auth="user")
def method(self, id, **kwargs):

cors='*'