I have a simple page that is being served by AngulraJs application. The page has div with a value of Test.
<div id="test">Test</div>
My goal is to read this value from localhost. Basically, I am writing a plugin for an application. This application is a desktop app that has its own web server built in and plugins are written in javascript. My goal is to read the test value. The problem that I am facing though is that I get prevented by CORS.
From everything I have read (and I have been reading a lot), I need to add the Access-Control-Allow-Origin
header in order for this to work. What my problem is how do I add a header with angular js for one page only.
I have found the follow SO answer: Set HTTP header for one request
I have also read a lot of documentation such as this: https://docs.angularjs.org/api/ng/service/$http
However, I am still confused with is one thing:
The url that is entered, what should it be in my case? Consider the following example, how would you write it to work for my case if the Angularjs app is sitting on www.somedomain.com and it is being called by javascript code from my localhost machine.
$http.get('what url goes here?', {
headers: {'Access-Control-Allow-Origin': '*'}
});
I also have a small sub question, with the above example, will I be overriding any of the existing headers or will it only append a new header?
EDIT:
Angularjs code serving back the page:
(function() {
'use strict';
angular
.module('App')
.controller('Test', Test);
function Test($scope, $http) {
var T = this;
T.test = test;
function test(){
return "Test";
}
}
})();
HTML
<div id="test">{{T.test()}}</div>