当您在创建 RestApi 时创建 CustomDomain 或在 CDK 中创建 RestApi 后添加 .addDomainName 时,将为指定阶段创建到域根目录的默认基本路径映射。
我不希望这样被创建。我想创建自己的基本路径映射。当我通过 domain.addBasePathMapping() 添加一个时,我最终得到了到根的映射和到指定基本路径的映射。像这样:
- api: example.com / stage: dev / path: (none) // 不想要这个。
- api:example.com/stage:dev/path:the-base-path //想要这个。
有没有办法改变默认的基本路径映射或阻止它被创建?
代码重现了这个问题:
const apiSpec = <openapi spec loaded here>
const zone = route53.HostedZone.fromLookup(this, 'theZone', {
domainName: 'example.com'
});
//Get the existing certificate
const acmCertificate = acm.Certificate.fromCertificateArn(this, 'Certificate', CERTIFICATE_ARN);
const apiDomainName = 'example.com';
const theApi = new apigateway.SpecRestApi(this, `the-example-api`, {
deploy: true,
restApiName: 'ApiNameHere',
deployOptions: {
stageName: 'dev',
},
endpointTypes: [ apigateway.EndpointType.REGIONAL ],
apiDefinition: apigateway.ApiDefinition.fromInline(apiSpec),
endpointExportName: `endpointExportName`,
domainName: {
domainName: apiDomainName,
certificate: acmCertificate,
securityPolicy: apigateway.SecurityPolicy.TLS_1_2
}
});
const domain = theApi.domainName
domain.addBasePathMapping(theApi, {basePath: 'the-base-path', stage: theApi.deploymentStage});
//Create alias record to route to apis
const aRecord = new route53.ARecord(this, 'alias-record', {
recordName: apiDomainName,
zone,
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(theApi))
});