What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello#help Iam trying to set up the react app example from the documentation but i keep getting the

U019GT49XKQ
U019GT49XKQ Posts: 16 🧑🏻‍🚀 - Cadet

Hello#help Iam trying to set up the react app example from the documentation but i keep getting the CORS error for /guest-cart s. can somebody tell me where exactly i need to set the access-control-allow-origin and access-control-allow-credentails headers. i tried setting them in docker/generator/src/templates/nginx/http/glue.server.conf.twig but that did not help. some of the CORS exceptions were fixed but the one from /guest-carts never goes away.

Comments

  • Andriy Netseplyayev
    Andriy Netseplyayev Domain Lead Solution Architecture Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    Hi Moe, it seems like the “allow-credentials” header is missing.
    To verify that this is the problem, I can suggest one dirty hack you can try locally.
    Please add the following to your public/Glue/index.php:

    if (strtoupper($_SERVER['REQUEST_METHOD']) === 'OPTIONS') {
       header('Access-Control-Allow-Origin: *');
       header('Access-Control-Allow-Credentials: true');
       header('Access-Control-Allow-Headers: origin, accept, authorization, accept-language, access-control-allow-methods, access-control-allow-origin, content-type, x-anonymous-customer-unique-id');
       header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PATCH, DELETE');
       header('Content-Type: text/plain');
       header('Content-Length: 0');
       http_response_code(204);
       exit(0);
     }
    

    If that would solve the issue, and you can confirm that Access-Control-Allow-Credentials - then the right way to solve it would be:
    1. Please report the problem to Spryker so we can fix that internally
    2. Have a look at \Spryker\Glue\GlueApplication\Rest\Response\ResponseHeaders - this is where the headers are being built; This class is extendable via plugins, so what you would need to do is to implement \Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\FormatResponseHeadersPluginInterface where you would add your missing header
    I hope that helps

  • U019GT49XKQ
    U019GT49XKQ Posts: 16 🧑🏻‍🚀 - Cadet

    Thank you @UKJSE6T47 . That helped!. iam able to load the app by making the changes to index.php. i will try to make the changes by implementing the pluginInterface..

  • Andriy Netseplyayev
    Andriy Netseplyayev Domain Lead Solution Architecture Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    Great, thanks for the feedback @U019GT49XKQ
    Please let me know eventually - whether the issue was with the missing header in ResponseHeaders part..

  • Andriy Netseplyayev
    Andriy Netseplyayev Domain Lead Solution Architecture Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    ..and just to remind again - changing the public/Glue/index.php - is a quick dirty hack, it must not be treated as a recommended solution 🙂