Rest API Cors issue

Hi,

I am running into some trouble utilizing Plone's rest api, getting stuck on some CORS issues.

I've attempted a couple of things,

First -
Updated configure.zcml to contain a CORSPolicy

    <plone:CORSPolicy
  allow_origin="*"
  allow_methods="DELETE,GET,OPTIONS,PATCH,POST,PUT"
  allow_credentials="true"
  allow_headers="Accept,Authorization,Origin,X-Requested-With,Content-Type,Upload-Length,Upload-Offset,Tus-Resumable,Upload-Metadata"
  for="Products.CMFPlone.interfaces.IPloneSiteRoot"
  expose_headers="Upload-Offset,Location,Upload-Length,Tus-Version,Tus-Resumable,Tus-Max-Size,Tus-Extension,Upload-Metadata"
  max_age="3600"
  />

Did not have any luck after restarting plone with that, I then tried adding the policy to the buildout.cfg
based on this from this thread

buildout.cfg -

[instance]
zcml-additional =
  <configure xmlns="http://namespaces.zope.org/zope"
             xmlns:plone="http://namespaces.plone.org/plone">
  <plone:CORSPolicy
    allow_origin="*"
    allow_methods="DELETE,GET,OPTIONS,PATCH,POST,PUT"
    allow_credentials="true"
    expose_headers="Content-Length,X-My-Header"
    allow_headers="Accept,Authorization,Content-Type,X-Custom-Header,Origin"
    max_age="3600"
    />
  </configure>

Ran bin/buildout and started plone back up but am still running into CORS issues, is there something else that needs to be configured?

Thanks!

1 Like

Got this worked out.

The zcml-additional in buildout.cfg ended up needing to be

zcml-additional =
  <configure xmlns="http://namespaces.zope.org/zope"
             xmlns:plone="http://namespaces.plone.org/plone">
  <plone:CORSPolicy
    for="Products.CMFPlone.interfaces.IPloneSiteRoot"
    layer="myproduct.interfaces.IMyBrowserLayer"
    allow_origin="*"
    allow_methods="DELETE,GET,OPTIONS,PATCH,POST,PUT"
    allow_credentials="true"
    expose_headers="Content-Length,X-My-Header"
    allow_headers="Accept,Authorization,Content-Type,X-Custom-Header,Origin"
    max_age="3600"
    />
  </configure>
2 Likes