nitric icon indicating copy to clipboard operation
nitric copied to clipboard

CORS helpers

Open jyecusch opened this issue 2 years ago • 2 comments

While CORS can currently be handled using middleware and by registering OPTIONS routes, we'd like to build this support into the framework to make it more convinient and ideally handle the responses as high up the infra stack as possible. For example, providing support for static responses to OPTIONS requests at the API Gateway or Nitric Server layers to reduce latency and hosting costs.

This support will be needed in all language SDKs.

jyecusch avatar Oct 17 '23 21:10 jyecusch

Research of cloud provider API gateway pulumi configs:

AWS: Seems pretty easy, just put them in apigatewayv2.NewApi

  • allowCredentials
  • allowHeaders
  • allowMethods
  • allowOrigins
  • exposeHeaders
  • maxAge

Azure: Need to create a cors policy use apimanagement.NewApiOperationPolicy

  • allowCredentials
  • allowHeaders
  • allowMethods
  • allowOrigins
  • exposeHeaders
  • maxAge

GCP: The worst of the bunch it seems, they suggest using ESP or doing it per function. References: https://stackoverflow.com/questions/64281334/cors-errors-when-trying-to-fetch-from-new-google-cloud-api-gateway/65738206#65738206 https://www.googlecloudcommunity.com/gc/Serverless/CORS-issue-with-API-gateway/m-p/619097

TLDR

AWS and Azure seem fine, however considering GCPs lack of support (and lack of a roadmap) Like we have suggested, we could use a load balancer or just handle it on our side, but then if we do this should we just do it consistently across any new provider or pick best prac per cloud?

davemooreuws avatar Oct 18 '23 05:10 davemooreuws

Another item for discussion. Should we also include bucket CORS configuration as a new ticket?

davemooreuws avatar Oct 18 '23 06:10 davemooreuws

Started work on proto contracts / integration with AWS.

davemooreuws avatar Oct 19 '23 05:10 davemooreuws

Is the Bucket CORS suggestion for people who want to access the bucket from a resource other than our API?

raksiv avatar Oct 24 '23 03:10 raksiv

Is the Bucket CORS suggestion for people who want to access the bucket from a resource other than our API?

Yes, but should be a new ticket if we decide to do it

davemooreuws avatar Oct 24 '23 03:10 davemooreuws

This has been completed and is ready for review (in this order):

  • https://github.com/nitrictech/nitric/pull/539 Then
  • https://github.com/nitrictech/cli/pull/595
  • https://github.com/nitrictech/node-sdk/pull/206

davemooreuws avatar Nov 05 '23 22:11 davemooreuws