CORS question: How do I setup the `ApolloApi` to a...
# sst
c
CORS question: How do I setup the 
ApolloApi
 to allow for CORS requests while being authenticated by Cognito Pool? The Apollo API seems to be failing on the preflight 
OPTIONS
 request. If I add an OPTIONS route manually to the ApiGateway with no authorization, the calls succeed and I can make graphql queries. But I’m not sure how to configure the route from the
ApolloApi
level as the 
routes
 param is disabled… It seems that when the Apollo API is created with a UserPoolAuthorizer, it authenticates on all routes/http methods including OPTIONS which according to the CORS spec should not have auth headers. Trying to find a way to disable that without manually updating the gateway. Any thoughts here?
Copy code
// current config
const api = new sst.ApolloApi(this, 'apollo-v2', {
      server: 'src/index.handler',
      defaultAuthorizationType: sst.ApiAuthorizationType.JWT,
      defaultAuthorizer: new HttpUserPoolAuthorizer({
        userPool,
        userPoolClient,
      }),
      cors: {
        allowOrigins: ['localhost:3000'],
        allowHeaders: ['*'],
        allowMethods: [CorsHttpMethod.ANY],
        allowCredentials: true,
      },
    })
f
Let me take a look.
Hey @colin I submitted a PR with the fix https://github.com/serverless-stack/serverless-stack/pull/591
I will cut a release tonight with the fix. Will keep you posted.
@colin This is fixed in v0.35.1
You can remove the
OPTIONS
route manually created in the APIG console.
Give it a try and let me know if this works for you!
c
oh sweeet!!
let me test this out