• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Node.js SDK)
  4. Static Website Hosting
  5. Viewing Website Hosting Settings

Viewing Website Hosting Settings

You can call ObsClient.getBucketWebsiteConfiguration to view the hosting settings of a bucket. Sample code is as follows:

// Import the OBS library.
var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'yourdomainname'
});

obsClient.getBucketWebsiteConfiguration({
       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.RoutingRule;i++){
                           console.log('RoutingRule[' + i + ']:');
                           let RoutingRule = result.InterfaceResult.RoutingRules.RoutingRule[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']);
                     }
              }
       }
});