Errors with CORS !
Hi everybody,
I'm trying to authenticate into bonita API REST, using AngularJs , but it doesn't work, because i have this error :
XMLHttpRequest cannot load http://localhost:8080/bonita/loginservice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
I investigated , and i can say that the problem is caused by CORS , because i have installing my apache server in http://localhost:80 and my bonita porta is in http://localhost:8080 and as you can see i have different domain because my app client is running in http://localhost:80 and my API REST are in http://localhost:8080 . I 'm new in AngularJs and my code is:
`'use strict';
(function(){
var appMainModule = angular.module('appMainModule',['ngBonita']);
appMainModule.config(function(bonitaConfigProvider){
bonitaConfigProvider.setBonitaUrl('http://localhost:8080/bonita');
});
appMainModule.controller('AppController',['$scope','$log','bonitaConfig','bonitaAuthentication','ProcessDefinition','HumanTask',function($scope,$log,bonitaConfig,bonitaAuthentication,ProcessDefinition,HumanTask){
bonitaAuthentication.login('root.root','root').then(function(){
$log.log('Usuari logejat: '+bonitaConfig.getUserName() + '(identificador: '+ bonitaConfig.getUserId() +')');
})}])
})();`
When i was investigating i found an solution like this:
var appMainModule = angular.module('appMainModule',['myAppApiService']);
appMainModule.config(['$httpProvider', function($httpProvider){
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);*/
But i don't know , how to integrate it in my code.
Regards
Hi all,
As I understand it, the problem is CORS related? The web browser detected that the content is served from 2 different locations, which violates the browsers Same-Origin policies .
As mentioned in the referred link. I experienced a similar issue and the only solution I found was to serve the webpages from the same web server as the Bonita BPM instance.
Kind regards
Pieter
Comments
You say:
...because i have installing my apache server in http://localhost:80 and my bonita porta is in http://localhost:8080 and as you can see i have different domain because my app client is running in http://localhost:80 and my API REST are in http://localhost:8080..
My understanding is you DO NOT have a different domain, you have ONE domain localhost, with two ports open for different applications.
Don't think that changing ports changes the domain.
Have a look here:
http://www.sitepoint.com/working-around-origin-policy/
https://jvaneyck.wordpress.com/2014/01/07/cross-domain-requests-in-javascript/
http://stackoverflow.com/questions/20433655/no-access-control-allow-origin-header-is-present-on-the-requested-resource-or
http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource
They all say because you are using the same domain....
Anyway - these are the four top answers from Google Search. Hope they help,
regards