To Whom it may concern:
I like to implement redirect action after amp-form submit. It's kind of strange with CORS header and always occur the following error message:

I am sure the CORS is correct (I've already use it in different feature, such as "like" and it works well).
Here comes some information about this issue:
Scenario:
I like this item and try to purchase it after login. Then I press the "direct buy button".
Expect: It should redirect to my checkout flow page after form submit.
Actually: "AMP-Access-Control-Allow-Source-Origin" error occur.
Response Header:

Web service:
https://blog.lalacube.com/mei/WS_mall_purchase_amp.php
I wonder is it an issue or do I need to set extra header ?
Have a nice day.
Paul
/to @cvializ /cc @aghassemi
Hi @meistudioli thanks for opening this issue! Access-Control-Expose-Headers needs to contain all non-standard headers that need to be exposed. Both AMP-Redirect-To and AMP-Access-Control-Allow-Source-Origin must be in the list of Access-Control-Expose-Headers for the server to receive them both correctly.
e.g.
Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin
It looks like only AMP-Redirect-To is present above. Try adding that header, and let us know if that solves your problem.
Hi, @cvializ:
I checked my code and figure out I rewrite the "Access-Control-Expose-Headers" orz. Everything is fine after I add AMP-Access-Control-Allow-Source-Origin in the Access-Control-Expose-Headers.
Here is my code:
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
...
...
...
if (purchaseSuccess) {
header('AMP-Redirect-To: https://tw.sc.mall.yahoo.com/mcart/preview');
header('Access-Control-Expose-Headers: AMP-Redirect-To, Another-Header, And-Some-More');
}
Kind of stupid about this orz.
By the way. Is it possible to make it more clear in amp-form document about redirect section ? I think other developers may just copy / paste the sample code like me.
amp-form: redirecting-after-a-submission
Thank you again for helping solving.
Paul
That's a great idea, we should update that documentation. Thanks for letting us know how you fixed it and suggesting an improvement 馃槂
Most helpful comment
Hi @meistudioli thanks for opening this issue!
Access-Control-Expose-Headersneeds to contain all non-standard headers that need to be exposed. BothAMP-Redirect-ToandAMP-Access-Control-Allow-Source-Originmust be in the list ofAccess-Control-Expose-Headersfor the server to receive them both correctly.e.g.
It looks like only
AMP-Redirect-Tois present above. Try adding that header, and let us know if that solves your problem.