I have a list on sharepoint where I am tracking tasks.
I am trying to create an electron app that will ping (http get request) this list every minute or so and display a little window with all the tasks the current user has assigned and highlight new tasks.
I am using the fetch API to access the list as follows:
const _COLLAB_ROOT = "http://company.com/projects/team-site/_vti_bin/listdata.svc/"
export function read(list, callback) {
const myHeaders = new Headers({
"Accept": "application/json",
'Authorization': 'Basic '+btoa('username:password'),
'Access-Control-Allow-Origin': '*'
});
const myInit = {
method: 'GET',
headers: myHeaders,
mode: 'no-cors'
}
fetch(_COLLAB_ROOT+list,myInit)
.then(response => {
if (response.ok) {
response.json().then(data => {
callback(data.d);
});
}
return Promise.reject(Error('error'))
}).catch(error => {
return Promise.reject(Error(error.message))
})
}
Other module:
read('listname',data => {
console.log(data);
})
However when I send this request with a list name filled in, I get the following:
Now I assume this has something to do with CORS. What I would like to know is, is there a way to get this working?
It seems like something very obvious to be required in electron.
Also I have set the we-preferences property to
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: true,
'web-preferences': {'web-security': false}
});
Any help is appreciated here. I will be really surprised if this is not possible so hopefully I am being dumb!
You're using the old webPreferences syntax, your constructor should look something this :)
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: true,
webPreferences: {
webSecurity: false
}
});