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

Setting CORS headers #182

Open
fthues opened this issue Dec 18, 2019 · 3 comments
Open

Setting CORS headers #182

fthues opened this issue Dec 18, 2019 · 3 comments

Comments

@fthues
Copy link

fthues commented Dec 18, 2019

We're submitting data to the plugin from a different domain. We're setting the required CORS headers via .htaccess (so the OPTIONS request goes through) but Craft seems to remove them from the actual POST request, which seems to be a problem for Axios.

The way I see it there is no way of overriding the controller to add headers to the response. Any hints as to how to approach this?

Thanks!

@ignism
Copy link

ignism commented Sep 16, 2020

Did you ever solve this? I’m running into similar problems.

@steveDL
Copy link

steveDL commented Oct 9, 2020

I have a similar issue POSTing to http://myurl.com/actions/contact-form/send. CURL returns a bunch of HTML and errors one starting with yii\web\BadRequestHttpException Post request required in /backend/vendor/craftcms/cms/src/web/Controller.php:356

But I guess this is result of not passing it what it needs as its a bad request. I trying to compose a valid request.

@danbrellis
Copy link
Contributor

danbrellis commented Feb 24, 2023

I know it's an old thread, but for anyone else with the same problem, one way I just solved dealing with the necessary headers for POST requests is to add the header in a custom module:

//modules/Module.php
Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', 'http://localhost:2222');

If that's too open for you, I'm sure you could add conditionals to check the type of request, the action, etc.

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

4 participants