import * as apig from "aws-cdk-lib/aws-apigateway" ; import * as sst from "@serverless-stack/resources" ; export class MainStack extends sst . Stack { constructor ( scope , id , props ? ) { super ( scope , id , props ) ; const authorizerFn = new sst . Function ( this , "MyAuthorizerFunction" , { handler : "src/authorizer.main" , } ) ; const authorizer = new apig . RequestAuthorizer ( this , "MyAuthorizer" , { handler : authorizerFn , identitySources : [ apig . IdentitySource . header ( "Authorization" ) ] , } ) ; const api = new sst . ApiGatewayV1Api ( this , "LegacyApi" , { cors : true , accessLog : true , customDomain : "v1.sst.sh" , defaultFunctionProps : { environment : { TABLE_NAME : "dummy" , } , } , defaultAuthorizer : authorizer , defaultAuthorizationType : apig . AuthorizationType . CUSTOM , routes : { "GET /" : "src/lambda.main" , "GET /sub" : "src/lambda.main" , "POST /sub" : "src/lambda.main" , "ANY /{proxy+}" : "src/lambda.main" , } , } ) ; api . restApi . addGatewayResponse ( "UNAUTHORIZED" , { type : apig . ResponseType . UNAUTHORIZED , responseHeaders : { "WWW-Authenticate" : "'Basic realm=\"Secure Area\"'" , } , } ) ; } }