0

I get this error when I try to run a JavaScript application which is embedded in my browser:

browser.html:1 Failed to load https://iam.bluemix.net/oidc/token: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

This is my webpage:

<!DOCTYPE html>
<html>
  <head>
    <script src="bundle.js"></script>
  </head>
  <body>
    <h1>A Web Page</h1>
    <p id="demo">A Paragraph</p>
  </body>
</html>

I run it locally by opening /path/to/browser.html in a browser.

This is the content of browser.js:

var cos = require('ibm-cos-sdk');

var config = {
  endpoint: 'endpoint',
  apiKeyId: 'api_key',
  serviceInstanceId: 'instance_id',
  ibmAuthEndpoint: 'https://iam.bluemix.net/oidc/token',
  s3ForcePathStyle: true
};

var cos = new cos.S3(config);
var bucket = 'bucket_name';

function doCreateBucket() {
  return cos.createBucket({
    Bucket: bucket,
      CreateBucketConfiguration: {
    }
  }).promise();
}

doCreateBucket();

bundle.js is generated from it with browserify browser.js -o bundle.js.

Is there any way around this?

Additional info

I came across something online that suggested my issue was because was accessing the page lacally with file:// and that I should try http:// so I deployed the page to a webserver and accessed it through http but this made no difference.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • Based on that snippet: You want to access a COS bucket from your browser and to have the credentials in the browser? What is the purpose of that app? – data_henrik Oct 10 '18 at 08:07
  • It doesn't have any significant purpose. I'm just experimenting a bit with the SDK. – runnerpaul Oct 10 '18 at 08:13

0 Answers0