https://supertokens.com/ logo
Title
a

Ayush6543

12/17/2022, 2:50 PM
Hey, I have just migrated my api from digital ocean to AWS lambda. After doing all the necessary steps, I am getting CORS, error,
signin:1 
 Access to fetch at 'https://8fx6k5jmyg.execute-api.eu-central-1.amazonaws.com/auth/session/refresh' from origin 'https://loquacious-crostata-a45e75.netlify.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
r

rp

12/17/2022, 3:03 PM
Hey @Ayush6543
Have you followed our aws setup guide?
We have explicit steps on how to configure for CORS
a

Ayush6543

12/17/2022, 5:11 PM
Using the editor provided by AWS, create a new config file and write the following code:
I am not seeing any editor.
r

rp

12/17/2022, 5:14 PM
Which page are you referring to?
I am using express, but it is saying to modify the framework to awsLambda
r

rp

12/17/2022, 5:46 PM
If you are using express, you can continue to use express framework
a

Ayush6543

12/17/2022, 5:50 PM
I mean I am using express and have deployed my app to aws lambda, When I try to sign in it gives me the CORS error, and I am following the guide to setup.
And did you notice the CORS error above, the url is missing the /dev, when I have explicity added /dev/auth in the api base path.
r

rp

12/17/2022, 6:26 PM
The /dev should be in apiGatewayPath config and apiBasePath should be /auth
a

Ayush6543

12/18/2022, 3:02 AM
Is it ok to use
cors
instead of
@middy/http-cors @middy/core
r

rp

12/18/2022, 3:02 AM
Yea. If you are using express, then you should not use middy
a

Ayush6543

12/18/2022, 3:07 AM
Should I set
isInServerlessEnv: true,
when I am using express as a framework to deploy on AWS Lambda.
r

rp

12/18/2022, 3:08 AM
Yes you should
a

Ayush6543

12/18/2022, 3:13 AM
In setting up API Gateway, and cors, it is saying to setup manually in the AWS console. But I am using serverless package. Can't I specify this is in my
serverless.yaml
. If so How? This is my
serverless.yaml
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
#    docs.serverless.com
#
# Happy Coding!

service: serverless-chrome-extension-app
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: "3"

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: eu-central-1

# you can overwrite defaults here
#  stage: dev
#  region: us-east-1



functions:
  hello:
    handler: app.server
    events: # events trigger lambda functions
      - http: # this is an API Gateway HTTP event trigger
          path: /
          method: ANY
          cors: true
      - http: # all routes get proxied to the Express router
          path: /{proxy+}
          method: ANY
          cors: true
r

rp

12/18/2022, 3:25 AM
Which serverless package are you using?
Also, you can use that, as long as it does the same things as specified in the manual steps
a

Ayush6543

12/18/2022, 3:28 AM
"serverless-http": "^3.1.0", serverless: 3.25
When I run the signin function the url is like https://8fx6k5jmyg.execute-api.eu-central-1.amazonaws.com/auth/session/refresh. Whereas the url I get after deployment is like https://8fx6k5jmyg.execute-api.eu-central-1.amazonaws.com/dev/. Why is supertokens not adding /dev.
r

rp

12/18/2022, 4:46 AM
You need to add /dev/auth in apiBasePath on the frontend
The backend apiBasePath is /auth and apiGatewayPath is /dev
a

Ayush6543

12/18/2022, 5:50 AM
Thanks
Worked.
r

rp

12/18/2022, 5:55 AM
Nice