该问题的解决方法是在 AWS CloudFront 分发中添加地图瓦片文件类型,以确保它们在缓存中正确地显示。这可以通过更新 CloudFront 配置进行完成。此示例展示如何为扩展名为“.png”的文件类型设置 CloudFront 分发:
var aws = require('aws-sdk');
aws.config.update({
region: 'us-west-2',
accessKeyId: '',
secretAccessKey: ''
});
var cloudfront = new aws.CloudFront();
var distributionId = '';
var params = {
DistributionId: distributionId,
DistributionConfig: {
CallerReference: new Date().getTime().toString(),
DefaultRootObject: 'index.html',
Origins: {
Quantity: 1,
Items: [
{
DomainName: '.s3.amazonaws.com',
Id: '',
S3OriginConfig: {
OriginAccessIdentity: ''
}
}
]
},
DefaultCacheBehavior: {
TargetOriginId: '',
TrustedSigners: {
Enabled: false,
Quantity: 0
},
ViewerProtocolPolicy: 'redirect-to-https',
ForwardedValues: {
QueryString: true,
Cookies: {
Forward: 'all'
},
Headers: {
Quantity: 0
},
QueryStringCacheKeys: {
Quantity: 0
}
},
MinTTL: 0,
AllowedMethods: {
Quantity: 2,
Items: [
'GET',
'HEAD'
],
CachedMethods: {
Quantity: 2,
Items: [
'GET',
'HEAD'
]
}
},
SmoothStreaming: false,
DefaultTTL: 86400,
MaxTTL: 31536000,
Compress: false,
LambdaFunctionAssociations: {
Quantity: 0
}
},
CacheBehaviors: {
Quantity: 1,
Items: [
{
PathPattern: