更新时间:2024-04-26 GMT+08:00
查看托管配置
您可以通过ObsClient.getBucketWebsite查看桶的托管配置。以下代码展示了如何查看托管配置:
// 创建ObsClient实例 var obsClient = new ObsClient({ // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量AccessKeyID和SecretAccessKey。 // 前端本身没有process对象,可以使用webpack类打包工具定义环境变量,就可以在代码中运行了。 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html access_key_id: process.env.AccessKeyID, secret_access_key: process.env.SecretAccessKey, // 这里以中国-香港为例,其他地区请按实际情况填写 server: 'https://obs.ap-southeast-1.myhuaweicloud.com' }); obsClient.getBucketWebsite({ Bucket: 'bucketname' }, function (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(var i in result.InterfaceResult.RoutingRules){ console.log('RoutingRule[' + i + ']:'); var 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']); } } } });
父主题: 静态网站托管