CORS error on Symfony API-Platform with Nelmio

  api-platform.com, cors, nelmiocorsbundle, symfony4

I am having on/off issues with CORS on my app setup with Nelmio CORS

Specifically, issue arises on /specs route, which should download pdf docs. All other seem to work fine.

The request headers correctly shows Origin as https://www.example.com

The web directory looks as below:

/backend
   /config
   ....
/public_html
    specs/
    images/
    .htaccess
    index.php

CORS config at /backend/config/packages/

nelmio_cors:
  defaults:
    allow_credentials: false
    allow_origin: ['^http://localhost:[0-9]+$','^https://www.example.com$', '^https://example-client.vercel.app.*$']
    allow_headers: ['X-Custom-Auth', 'Content-Type', 'Authorization']
    allow_methods: []
    expose_headers: ['Link']
    max_age: 360
    hosts: []
    origin_regex: true
    forced_allow_origin_value: ~
  paths:
    #'^/': null
    '^/api/':
            allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
            max_age: 3600
    '^/data/':
            allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
            max_age: 3600
    "^/specs.":
        allow_methods: ["GET", "OPTIONS"]
        max_age: 3600
    '^/spec/':
            allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
            max_age: 3600
    '^/':
            allow_methods: ['GET']
            max_age: 3600
            hosts: ['^api.']
    

Source: Symfony4 Questions

LEAVE A COMMENT