使用Electron将Angular Project(进行REST API调用)转换为桌面应用

I have a fully functional Angular Frontend who makes REST Api calls to a Spring Boot Backend who functions on the port 8080. I am in need to converting this web application to a desktop application. I got to know it is easy to use electron for this. I followed several threads under this question but couldn't find an answer. How can i achieve this by modifying this main.js file? Or do I need to modify everyplace within the project where it makes the api calls? I have the app loaded to the window, but it doesn't communicate with the Backend.

const {
app,
BrowserWindow
  } = require('electron')
  const url = require("url");
  const path = require("path");

  let appWindow

function initWindow() {
appWindow = new BrowserWindow({
  width: 1000,
  height: 800,
  webPreferences: {
    nodeIntegration: true
  }
})

// Electron Build Path
appWindow.loadURL(
  url.format({
    pathname: path.join(__dirname, `/dist/index.html`),
    protocol: "file:",
    slashes: true
  })
);

// Initialize the DevTools.
appWindow.webContents.openDevTools()

appWindow.on('closed', function () {
  appWindow = null
})}

app.on('ready', initWindow)

// Close when all windows are closed.
app.on('window-all-closed', function () {

// On macOS specific close process
if (process.platform !== 'darwin') {
  app.quit()
}
})

app.on('activate', function () {
if (win === null) {
  initWindow()
}
})
评论