我正在使用Serverless来创建一个Web应用程序,该应用程序从S3存储桶提供静态内容,例如Web字体.S3存储桶配置为serverless.yml文件中的资源.其CORS配置将AllowOrigin设置为通配符.
我想将此更改为具有AllowOrigin,其中包含由Serverless创建的服务的http端点,例如31alib51b6.execute-api.eu-west-1.amazonaws.com
.
我想知道是否可以在serverless.yml文件中配置它.
我的示例serverless.yml文件:
service: example-service provider: name: aws runtime: nodejs4.3 region: eu-west-1 functions: web: handler: handler.handler name: ${self:service}-${self:provider.stage} description: ${self:service} web application - ${self:provider.stage} events: - http: path: web method: get - http: path: web/{proxy+} method: get resources: Resources: S3Assets: Type: AWS::S3::Bucket Properties: BucketName: ${self:service}-${self:provider.stage}-assets CorsConfiguration: CorsRules: - AllowedMethods: - GET - HEAD AllowedOrigins: - "*"
jens walter.. 8
您可以使用以下语句定义AllowedOrigin:
CorsConfiguration: CorsRules: - AllowedMethods: - GET - HEAD AllowedOrigins: - Fn::Join: - "" - - "https://" - Ref: ApiGatewayRestApi - ".execute-api.eu-west-1.amazonaws.com"
"Ref:ApiGatewayRestApi"引用生成的API的内部名称.
您可以使用以下语句定义AllowedOrigin:
CorsConfiguration: CorsRules: - AllowedMethods: - GET - HEAD AllowedOrigins: - Fn::Join: - "" - - "https://" - Ref: ApiGatewayRestApi - ".execute-api.eu-west-1.amazonaws.com"
"Ref:ApiGatewayRestApi"引用生成的API的内部名称.