Enabling CORS

cancel
Showing results for 
Search instead for 
Did you mean: 
eugenio_romano
Alfresco Employee

Re: Enabling CORS

Jump to solution

what do you have in the app.config.json?

jriedl17
Active Member

Re: Enabling CORS

Jump to solution

Now I have both, the ADF-APP and the Alfresco-Instance, on the same server. However I still get the CORS-Error.

app.config.json:

eugenio_romano
Alfresco Employee

Re: Enabling CORS

Jump to solution

Are they on the same port? If port numbers are different the request is considered cross-domain.

A configuration that should work for sure from your localhost if correctly configured should be like that 

proxy.conf.js 

module.exports = {
  "/alfresco": {
    "target": "http://yourContentService.com",
    "secure": false,
    "pathRewrite": {
      "^/alfresco/alfresco": ""
    },
    "changeOrigin": true,
    // workaround for REPO-2260
    onProxyRes: function (proxyRes, req, res) {
      const header = proxyRes.headers['www-authenticate'];
      if (header && header.startsWith('Basic')) {
          proxyRes.headers['www-authenticate'] = 'x' + header;
      }
    }
  },
  "/activiti-app": {
    "target": "http://yourprocessService.com",
    "secure": false,
    "pathRewrite": {
      "^/activiti-app/activiti-app": ""
    },
    "changeOrigin": true
  }
};

the app.config.json has you posted should be fine.

The last doubt that I have is how you start your project. Which command do you use?

npm run start? If you use npm run start what is npm run start in your package.json?

ranjeetsi
Established Member II

Re: Enabling CORS

Jump to solution

Hi,

I had faced similar situation some time back : please check if this works for you:

On the alfresco backend server - https://community.alfresco.com/external-link.jspa?url=http%3A%2F%2Falfresco.mbasoft.at%3A8080 

you will have to do change in the web.xml to allow a wildcard support for origins.

<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
And then - whitelist your fronend url at the web proxy layer - if you have .
Also if you have load balancer , web proxy configured before the backend - you need to have the wildcard * , or your frontend url , so that it does not drop your header at any point.
You can run curl commands on urls at each level web proxy ->load balancer -> alfresco to see where the header is dropped .
Since your error is:
==========================
No 'Access-control-allow-origin" header is present on the requested resource(backend)
Thanks!
Alfresco Content Services Certified Engineer (ACSCE)
jriedl17
Active Member

Re: Enabling CORS

Jump to solution

Yes they are on the same port. Both are running on port 8080. I haven't used any start command, I have built it with "ng build --base-href /myUrl/" and added the dist folder to the webapp folder of my tomcat.

eugenio_romano
Alfresco Employee

Re: Enabling CORS

Jump to solution

If you just create the build and after you move it in tomcat at this point the proxy configuration is not important anymore because you don't use anymore webpack dev server but you can take a look at how to disable CORS in Apache :

https://community.alfresco.com/community/application-development-framework/blog/2017/06/20/adf-cors-... 

If correctly disabled CORS you should not have any error about CORS, anyway, this is not a suggested configuration for security issues but it could be a good point to understand where are your problems.

This is for sure not an ADF issue but is more an APACHE configuration issues so I suggest you read more about this topic and concentrate your time in solving CORS problems in APACHE Tomcat.

I didn't understand if you never try to run your app on your local machine before. Anyway if you would try and you created your app with the app generator I suggest you use :

npm run start

This is because this command contains inside the configuration for use the webpack proxy :

ng serve --host 0.0.0.0 --disable-host-check --app dev --proxy-config ./demo-shell/proxy.conf.js

but again this proxy configuration is only needed in the local development and is not affecting in any way your deployed app in apache.

jriedl17
Active Member
eugenio_romano
Alfresco Employee

Re: Enabling CORS

Jump to solution

Cool! no problem!