Sitecore / jss

Software development kit for JavaScript developers building web applications with Sitecore Experience Platform
https://jss.sitecore.com
Apache License 2.0
262 stars 272 forks source link

Elastic Load Balancer does not support sc_apikey header #1060

Closed thaiphan closed 2 years ago

thaiphan commented 2 years ago

Description

I'm trying to use the GraphQLSitemapService. However, I'm getting the following error:

SSC API key is required. Pass with 'sc_apikey' query string or HTTP header.

It turns out that Elastic Load Balancer strips out non-standard custom headers.

Possible Fix

It looks like GraphQLRequestClient passes sc_apikey as a HTTP header. Is it possible to switch it so that it's a query param? Or configure it so we can choose one or the other...

https://github.com/Sitecore/jss/blob/f1fd3f1e17906162c70c055d94b4cff70daa88df/packages/sitecore-jss/src/graphql-request-client.ts#L52

Elyseum commented 2 years ago

Similar issue for running Sitecore in K8s behind nginx (underscore is not allowed by default, the issue + fix is documented in Sitecore 10.2 installation PDF -- unfortunately it's not index by Google so it was quite hard to find :().

Nick Wesselman worked around this by modifying his generate-config file. It includes the sc_apikey as query string parameter in the GraphQL URL. See https://github.com/Sitecore/Helix.Examples/blob/master/examples/helix-basic-nextjs/src/Project/BasicCompany/nextjs/scripts/generate-config.ts

ambrauer commented 2 years ago

This was switched to a header by default with the introduction of Experience Edge (JSS 18, see #636) as a header is required here.

You can use a query string by modifying the generate-config.ts in your app as suggested above (here's the pre-edge version, which is what the referenced Helix.Examples is using).