I've been trying to create a simple function using the Office JavaScript API to log into my company's on-prem server hosted at my local machine and fetch a response back. I have used Vue JS
as my front-end framework with axios
for HTTP/S requests.
Here's the code for the axios call:
import Vue from "vue";
import Vuex from "vuex";
const axios = require('axios').default;
axios.defaults.crossDomain = true;
Vue.use(Vuex);
/**
* Network interactions and state manager
*/
const Network = new Vuex.Store({
state: {
url: 'http://127.0.0.1', //localhost by default
user: '',
pass: ''
},
getters: {
},
mutations: {
setLoginCreds(state, payload) {
state.url = payload.url;
state.user = payload.user;
state.pass = payload.pass;
},
},
actions: {
async login(context, { url, user, pass }) {
let route = '/core/loginguest';
let path = url + route;
await axios({
url: path,
method: 'POST',
params: {
userid: user,
password: pass
}
}).then(response => {
console.log(response)
if (response.status == 200) {
context.commit('setLoginCreds', { url, user, pass })
}
}).catch(err => {
console.log('Exception hit!')
console.log(err)
})
},
}
});
export default Network;
While running this on Word, I get the following error at login(as viewed using Microsoft Edge dev Tools):
SEC7120: [CORS] The origin 'https://localhost:3000' did not find 'https://localhost:3000' in the Access-Control-Allow-Origin response header for cross-origin resource at 'http://127.0.0.1/core/loginguest?userid=hari&password=hari1234'.
As per my understanding, the CORS issue arises from Access-Control-Allow-Origin: *
not being present in the response header of the server, but I did not experience this when using the same calls on Electron.js.
Is it just another CORS issue which puts me at the mercy of the server or is it something that I can control from client-end?