Hi, I am trying to solve CORS error in AWS API Gat...
# aws
m
Hi, I am trying to solve CORS error in AWS API Gateway connected with AWS Lambda. Can anyone help me fix this issue. Thanks:
Copy code
import json
import pulumi
import pulumi_aws as aws
import pulumi_aws_apigateway as apigateway

api = apigateway.RestAPI("api",
  routes=[
    apigateway.RouteArgs(
        path="/date", 
        method=apigateway.Method.GET, 
        event_handler=fn,
        authorizers=[],
        request_validator=apigateway.RequestValidator.ALL,
    ),
    apigateway.RouteArgs(
        path="/postdate", 
        method=<http://apigateway.Method.POST|apigateway.Method.POST>, 
        event_handler=fn,
        authorizers=[],
        request_validator=apigateway.RequestValidator.ALL,
    ),
    # OPTIONS route for /date to handle CORS preflight requests
        apigateway.RouteArgs(
            path="/date",
            method=apigateway.Method.OPTIONS,
            data={
                "statusCode": 200,
                "headers": {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "GET,POST,OPTIONS",
                    "Access-Control-Allow-Headers": "Content-Type, Authorization",
                },
                "body": ""
            },
        ),
        # OPTIONS route for /postdate to handle CORS preflight requests
        apigateway.RouteArgs(
            path="/postdate",
            method=apigateway.Method.OPTIONS,
            data={
                "statusCode": 200,
                "headers": {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "GET,POST,OPTIONS",
                    "Access-Control-Allow-Headers": "Content-Type, Authorization",
                },
                "body": ""
            }
        )
  ]
)