更新时间:2023-11-09 GMT+08:00
查看托管配置
您可以通过ObsClient.getBucketWebsite查看桶的托管配置。以下代码展示了如何查看托管配置:
// 引入obs库 // 使用npm安装 var ObsClient = require('esdk-obs-nodejs'); // 使用源码安装 // var ObsClient = require('./lib/obs'); // 创建ObsClient实例 const obsClient = new ObsClient({ //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html access_key_id: process.env.ACCESS_KEY_ID, secret_access_key: process.env.SECRET_ACCESS_KEY, //这里以中国-香港为例,其他地区请按实际情况填写 server: 'https://obs.ap-southeast-1.myhuaweicloud.com' }); obsClient.getBucketWebsite({ Bucket: 'bucketname' }, (err, result) => { if(err){ console.log('Error-->' + err); }else{ console.log('Status-->' + result.CommonMsg.Status); if(result.CommonMsg.Status < 300 && result.InterfaceResult){ console.log('RedirectAllRequestsTo:'); console.log('HostName-->' + result.InterfaceResult.RedirectAllRequestsTo['HostName']); console.log('Protocol-->' + result.InterfaceResult.RedirectAllRequestsTo['Protocol']); console.log('IndexDocument[Suffix]-->' + result.InterfaceResult.IndexDocument['Suffix']); console.log('ErrorDocument[Key]-->' + result.InterfaceResult.ErrorDocument['Key']); console.log('RoutingRules:'); for(let i=0;i<result.InterfaceResult.RoutingRules;i++){ console.log('RoutingRule[' + i + ']:'); let RoutingRule = result.InterfaceResult.RoutingRules[i]; console.log('Condition[HttpErrorCodeReturnedEquals]-->' + RoutingRule['Condition']['HttpErrorCodeReturnedEquals']); console.log('Condition[KeyPrefixEquals]-->' + RoutingRule['Condition']['KeyPrefixEquals']); console.log('Redirect[HostName]-->' + RoutingRule['Redirect']['HostName']); console.log('Redirect[HttpRedirectCode]-->' + RoutingRule['Redirect']['HttpRedirectCode']); console.log('Redirect[Protocol]-->' + RoutingRule['Redirect']['Protocol']); console.log('Redirect[ReplaceKeyPrefixWith]-->' + RoutingRule['Redirect']['ReplaceKeyPrefixWith']); console.log('Redirect[ReplaceKeyWith]-->' + RoutingRule['Redirect']['ReplaceKeyWith']); } } } });
父主题: 静态网站托管