Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] CORS #2564

Closed
edwh opened this issue Feb 27, 2019 · 6 comments
Closed

[Question] CORS #2564

edwh opened this issue Feb 27, 2019 · 6 comments

Comments

@edwh
Copy link

edwh commented Feb 27, 2019

New to API Platform and Symfony, so be gentle. I have an app based on the instructions here; I can use it in local dev but get CORS issues from the Admin when accessing the API after deploying to platform.sh.

I have seen #1199, but that mentions files (e.g. parameters.yml) that don't exist in the sample, and seem to relate to other Symfony setups. I've tried making various changes, but feel like I'm just changing random code without knowing what I'm doing.

So I would be grateful if someone could give me some pointers to enable wildcard CORS on the API of a project generated using API Platform.

@norkunas
Copy link
Contributor

If you are using symfony flex, you should update CORS_ALLOW_ORIGIN in your api .env file

@edwh
Copy link
Author

edwh commented Feb 27, 2019

Thanks for your reply. How do I know whether something generated with API Platform is using symfony flex?

I can see that file, but I can see that some people have trouble setting it to a wildcard, e.g. nelmio/NelmioCorsBundle#99 . Would you expect it to work if I just change it to:

CORS_ALLOW_ORIGIN=*

I don't get any Access-Control-Allow-Origin headers back when I try that.

@norkunas
Copy link
Contributor

norkunas commented Feb 27, 2019 via email

@edwh
Copy link
Author

edwh commented Feb 27, 2019

That's what I've tried (I might have edited after you replied).

@norkunas
Copy link
Contributor

You mean you tried:

nelmio_cors:
    defaults:
        origin_regex: true
        allow_origin: ['*']
        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
        allow_headers: ['Content-Type', 'Authorization']
        max_age: 3600
    paths:
        '^/': ~

?

@edwh
Copy link
Author

edwh commented Feb 27, 2019

Ah, I see what you mean (jn api/config/nelmio_cors.yaml). Bingo, that works. Thank you.

@edwh edwh closed this as completed Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants