Enable CORS using Plone RESTAPI and Angular SDK

Hello everyone,

I'm developing an aplication using Angular 6 and Plone 5.1.4 with the Plone RESTAPI (https://github.com/plone/plone.restapi-angular)

Everything it's fine but i can't enable CORS on the Backend (Plone), I can't set the Access-Control-Allow-Origin, or I don't know how to do it.

The plone instance is running on the port 8080 of my server and the Angular application is running on the port 80 with Apache.

I've read this thread before and I tried to do what he mentions on the first comment, but it doesn't work.

Anyone have any leads or sugestion of how I can enable it?

Thanks for reading.

Hi @KeidaS,

You need to add a directive in your site.zcml. You will get all the details here:

1 Like

Thanks @ebrehault !!!!!!

This is how I solved it:

I added the following lines to the size.zcml (located on "zeocluster/parts/client1/etc/")

<configure

xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta"
xmlns:five="http://namespaces.zope.org/five"
xmlns:plone="http://namespaces.plone.org/plone">

<plone:CORSPolicy
allow_origin="*"
allow_credentials="true"
expose_headers="Content-Length,X-My-Header"
allow_headers="Accept,Authorization,Content-Type,X-Custom-Header"
max_age="3600"
/>

Finally I removed the <plone:CORSPolicy lines on the 999-additional-overrides.zcml located on "zeocluster/parts/client1/etc/package-includes".

Thanks again!!

I wouldn't customize the site.zcml directly if you use buildout.
Instead at the same zcml with a zcml-additional = parameter insid your instance part in your buildoud confiuration.

Here's an example: https://github.com/plone/volto/blob/master/api/buildout.cfg#L24

The example provided by @jaroel now lives here: https://github.com/plone/volto/blob/master/api/base.cfg#L24

1 Like