CORs Issues
Sometimes there are CORs issues on the Microfrontends or APIs that prevents Hackney sites from loading (blank page shows instead). If this issue occurs then the following will need to take place for both APIs and Microfrontends.
Update APIs:
Within the Startup.cs
page of the APIs the following code will need to be added to the ConfigureServices()
method:
services.AddCors();
If additional headers are required in the API then the folowing will need to be added to the Configure()
method:
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("ETag", "If-Match", "x-correlation-id"));
Within the Serverless.yml the following will need to be added to the events function:
events:
- https:
path: /{proxy+}
method: ANY
authorizer:
arn: ${ssm:/api-authenticator/${self:provider.stage}/arn}
type: request
resultTtlInSeconds: 0
identitySource: method.request.header.Authorization
managedExternally: true
cors:
origin: '*'
headers:
- Content-Type
- If-Match
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- x-correlation-id
allowCredentials: false
Microfrontends:
To forward the headers using legacy cache settings, follow these steps:
- Open your distribution from the CloudFront console.
- Choose the Behaviors tab.
- Choose Create Behavior. Or, select an existing behavior, and then choose Edit.
- Under Cache key and origin requests, select Legacy cache settings.
- In the Headers dropdown list, choose the headers required by your origin. If needed, choose Add custom to add headers required by your origin that are not in the dropdown list.
- Choose Save Changes. If you are creating the behavior, choose Create Behavior.