Hey, I have just migrated my api from digital ocea...
# support-questions-legacy
k
Hey, I have just migrated my api from digital ocean to AWS lambda. After doing all the necessary steps, I am getting CORS, error,
Copy code
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
Hey @kumar_ayush
Have you followed our aws setup guide?
We have explicit steps on how to configure for CORS
k
Using the editor provided by AWS, create a new config file and write the following code:
I am not seeing any editor.
r
Which page are you referring to?
I am using express, but it is saying to modify the framework to awsLambda
r
If you are using express, you can continue to use express framework
k
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
The /dev should be in apiGatewayPath config and apiBasePath should be /auth
k
Is it ok to use
Copy code
cors
instead of
Copy code
@middy/http-cors @middy/core
r
Yea. If you are using express, then you should not use middy
k
Should I set
Copy code
isInServerlessEnv: true,
when I am using express as a framework to deploy on AWS Lambda.
r
Yes you should
k
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
Copy code
serverless.yaml
. If so How? This is my
Copy code
serverless.yaml
Copy code
# 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
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
k
"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
You need to add /dev/auth in apiBasePath on the frontend
The backend apiBasePath is /auth and apiGatewayPath is /dev
k
Thanks
Worked.
r
Nice
2 Views