I'm using Webpack to bundle my javascript code and use modules in the browser.
I'm trying to get the body of a URL (http://www.redbubble.com); however, I get the following error:
XMLHttpRequest cannot load http://www.redbubble.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
This is the code I am bundling and making my request to grab the body html for http://www.redbubble.com (including this in my ejs under script tag reference)
var request = require('request');
var options = {
url: 'http://www.redbubble.com',
withCredentials: false
};
function callback(error, response, body) {
window.console.log("callback is being called");
if (!error && response.statusCode == 200) {
alert(body);
} else {
window.console.log(error);
}
}
request(options, callback);
I am also trying to use the CORS module in my app.js to resolve the Acces-Control-Allow-Origin
error, but it's no good.
app.use(cors({
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false
}));
Why is this error persisting? And how can it be resolved?