文档首页 > > SDK参考> Node.js> 静态网站托管> 查看托管配置

查看托管配置

分享
更新时间: 2019/04/22 GMT+08:00

您可以通过ObsClient.getBucketWebsite查看桶的托管配置。以下代码展示了如何查看托管配置:

// 引入obs
// 使用npm安装
var ObsClient = require('esdk-obs-nodejs');
// 使用源码安装
// var ObsClient = require('./lib/obs');

// 创建ObsClient实例
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'https://your-endpoint'
});

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']);
                     }
              }
       }
});
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区