I'm trying to make a get request from ADF to Alfresco comunity 7.0. Here is the code:
export class MydatatableComponent implements OnInit { constructor() { const alfrescoApi = new AlfrescoApi({ hostEcm: 'http://localhost:8080' }); const peopleApi = new PeopleApi(alfrescoApi); const opts = { 'skipCount': 56, /* | The number of entities that exist in the collection before those included in this list. If not supplied then the default value is 0. */ 'maxItems': 56 }; peopleApi.listPeople().then((data) => { console.log('API called successfully. Returned data: ' + data); }, function(error) { console.error(error); }); }
and here is the error I get from the console:
Access to XMLHttpRequest at 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people' from origin 'http://localhost:4200' 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.
and this my proxy.conf.js
module.exports = { "/alfresco/*": { "target": "http://localhost:8080", "secure": false, "changeOrigin": true } };
I did download enablecors-1.0 and copied it to modules/platform but it didn't work.
What is the problem and how I can fixit?
PS: I also tried to use apiService.getInstance().webScript.executeWebScript
and it didn't work.
Thank you in advance
Try using this setting in Alfresco Repository:
csrf.filter.enabled=false
You may add this property to alfresco-global.properties
I did add csrf.filter.enabled=false to my alfresco-global.properties and got the same error
Some additional info can be found here: https://hub.alfresco.com/t5/application-development/adf-cors-solving-strategies/bc-p/311055#M272
You proxy target needs to point to a remote ACS. So that your app calls localhost that is redirected by proxy. In your example, your proxy is having incorrect target and points to self
Discussions, help and advice about the Alfresco Development Framework.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.