Vesko Vujovic
Vesko Vujovic

Reputation: 400

No 'Access-Control-Allow-Origin' with NelmioCorsBundle

Hi i have this configuration for NelmioCorsBundle in Symfony framework:

nelmio_cors:
    paths:
        '^/note/':
            allow_origin: ['*']
            allow_headers: ['X-Custom-Auth']
            allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
            max_age: 3600

I still get No 'Access-Control-Allow-Origin' header is present on the requested resource.

I made two virtual hosts on my local machine one virtual host is client, other virtual host is restAPI.

Please help.

Upvotes: 2

Views: 1918

Answers (2)

Vesko Vujovic
Vesko Vujovic

Reputation: 400

If anyone have the same issue as i here is the answer.

I use Ubuntu. NelmioCorsBundle was already working the problem was with project folder privileges, when composer is installing this bundle it needs to clear app cache. If you don't set write permissions it won't be able to write in the cache directory.

It needs to add new configurations and write it in cache.

This was problem, after this everything worked.

I hope this helps.

Upvotes: 1

Sergei Kutanov
Sergei Kutanov

Reputation: 825

Here's my config:

nelmio_cors:
    paths:
        '/api':
            allow_origin: ['*']
            allow_headers: ['*']
            allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
            max_age: 3600

works fine, the only difference is in allow_headers value and path. Try it.

Upvotes: 0

Related Questions