bhargav barre

bhargav barre

  • NA
  • 8
  • 3.9k

Unable to read the back end api from Electron angular app

Feb 4 2020 11:35 PM
Im trying to fetch the data from the back end api in electron application. Origin as showing as "file://"
i tried to set the proxy for this but still not working. Please help me on this. 
Here is my code
const electron = require('electron')
const cors = require('cors');
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
const port = 3000
const path = require('path')
const url = require('url')
var fs = require('fs');
var pac = require('pac-resolver');
let mainWindow
let ProxyFunc
let pacVariable
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
app.commandLine.appendSwitch('proxy-server', '172.18.18.64');
var FindProxyForURL = pac(fs.readFileSync('dist/website/assets/pacfile.js'));
FindProxyForURL('https://172.18.18.64/api/rest/security/login').then((res) => {
});
mainWindow.webContents.session.setProxy({ proxyRules: 'https://172.18.18.64:8080' }, function () {
mainWindow.loadURL(path.join('file://', __dirname, 'dist/website/index.html'));
});
mainWindow.webContents.openDevTools({ mode: 'bottom' });
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', () => {
console.log('Ready');
createWindow();
});
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})