I got it working. If you use Angular, jQuery or any Javascript inside Electron, it will use the Browser's capabilities and therefore will also send the OPTIONS preflight if the POST has a complex media type, which was my case.
If you use Electron's http API, it does not do that. Documentation is here https://electronjs.org/docs/api/client-request
Here is my POC angular code using it:
const { net } = require('electron').remote;
const request = net.request(requestApi);
let requestApi = {
method: 'POST',
headers: {
'Content-Type': 'custom complex media type here',
'Authorization': 'Bearer ' + accessToken // if api is secured
},
protocol: 'https:',
hostname: 'hostname.com',
port: 443,
path: '/api/path/to/method'
};
request.on('response', (response) => {
console.log(`STATUS: ${response.statusCode}`);
resolve(response);
response.on('error', (error) => {
console.log(`ERROR: ${JSON.stringify(error)}`);
reject(error);
})
});
request.end(JSON.stringify(usageData));
Hope this helps.