express routes give 404 in electron app after deployment

Issue

This Content is from Stack Overflow. Question asked by Ali Shefaee

I have an electron that also run an express app.
in development mode everything works fine but after deployment and install app, express routes is not working.
screenshot

//package.json
{
  "build": {
    "extraResources": [
      "./extraResources/**"
    ]
  },
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build": "electron-builder -w",
    "build:gyp": "node-gyp rebuild"
  },
  "devDependencies": {
    "electron": "^20.1.4",
    "electron-builder": "^23.3.3",
    "node-gyp": "^9.1.0"
  },

}
//main.js
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
let server = require('./nodejs/server');  // this is express app
function createWindow () {
    const mainWindow = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences: {
        preload: path.join(__dirname, 'preload.js')
      }
    })
    mainWindow.loadFile(path.join( __dirname, '/front/index.html'));
    mainWindow.on('closed', () => app.quit());
  

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  createWindow()

  app.on('activate', function () {
    // On macOS 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 (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

I see with console.log() that express app is running in dev mode correctly.
but in production all apis fails



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?