Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apollo-server-lambda] allow regex support for Acess-Control-Allow-Origin #4470

Closed
sachinmour opened this issue Aug 10, 2020 · 4 comments
Closed

Comments

@sachinmour
Copy link

To enable CORS response for requests with credentials (cookies, http authentication) the allow origin header must equal the request origin.
Current cors options

  • origin: boolean | string | string[]

In the current scenario either we allow everything by setting it to true which will allow all domains, which is not ideal most of the times unless you're creating a public api.
Then there is an option of string array which makes it really hard to define all the possible subdomains and ports which are needed when developing locally.
I purpose to support regex array and/or regex which will really help to make sure you define exactly what you need in a very consistent manner.

For eg.

{
  origin: [/localhost:(.*)$/, /\.example\.com$/]
}
@iamnnort
Copy link

I have the same issue, is there a reason why the library does not support all options from Express? https://github.com/expressjs/cors#configuration-options

@dsuwirya
Copy link

dsuwirya commented Dec 6, 2020

I also need the ability to pass Function here as what expressjs cors middleware allows us to do. I'm using 'apollo-server-cloud-functions'.

prescottprue added a commit to prescottprue/apollo-server that referenced this issue Apr 1, 2021
…ow-Origin (apollographql#4470)

fix(apollo-server-cloud-functions): allow regex support for Access-Control-Allow-Origin (apollographql#4470)
@prescottprue
Copy link

+1 Took a bit of debugging to figure out what was going on, but seemed like we would just need to add regex matching as part of this if logic in ApolloServer

Took a stab at adding to both apollo-server-cloud-functions and apollo-server-lambda in this PR

@glasser
Copy link
Member

glasser commented Oct 11, 2022

Apollo Server 4 replaces a hard-coded set of web framework integrations with a simple stable API for building integrations. As part of this, the core project no longer directly supports a Lambda integration. Check out the @as-integrations/aws-lambda package; this new package is maintained by Lambda users and implements support for the API Gateway v1 and v2 protocols. If you need to work with different AWS projects, you may be able to add that support to that package, or take another approach such as combining the @vendia/serverless-express package with Apollo Server 4's built-in expressMiddleware (this is the same approach that apollo-server-lambda takes in AS3). Sorry for the delay!

@glasser glasser closed this as completed Oct 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants