title: Allow CORS on symfony 4
body: <p>I recently needed to allow CORS and on my search for a solution I found <code>nelmio/NelmioCorsBundle</code>.</p>
  
  <p>For the begging I can allow request from any origin, so this is my <code>app/config/config.yml</code>:</p>
  
  <pre><code>nelmio_cors:
      defaults:
          allow_credentials: false
          allow_origin: ['*']
          allow_headers: ['*']
          allow_methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
          max_age: 3600
          origin_regex: false 
  </code></pre>
  
  <p>It worked for GET requests only, any POST request returns:</p>
  
  <blockquote>
    <p>No 'Access-Control-Allow-Origin' header is present on the requested
    resource.</p>
  </blockquote>
  
  <p>I don't need necessarily to work with this bundle, at the begging i tried to uncomment <code>TRUSTED_HOSTS</code> and set it with my domain on <code>dotenv</code> file but it was for no use. Also I didn't found any help about this TRUSTED_HOSTS in docs.</p>
  
  <p>So any help with this bundle or any other solution to CORS on symfony I would be glad.</p>
  
  <hr>
  
  <p>As asked I'm updating with my current config of nelmiocors:</p>
  
  <pre><code># app/config/config.yml
  
  # Nelmio CORS Configuration
  nelmio_cors:
      defaults:
          origin_regex: true
          allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
          allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
          allow_headers: ['Content-Type', 'Authorization']
          expose_headers: ['Link']
          max_age: 3600
      paths:
          '^/':
            origin_regex: true
            allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
            # allow_origin: ['^http://localhost:[0-9]+']
            allow_headers: ['*']
            allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
            # allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
            max_age: 3600
            # hosts: ['^api\.']
  </code></pre>