Skip to content

Commit 37ee5ab

Browse files
committed
Fix mock server not working in packaged app
It boils down to: 1. We should call `fork` in main process (https://www.matthewslipper.com/2019/09/22/everything-you-wanted-electron-child-process.html) 2. We need to require the mock server when launched in packaged, production mode, similar to how express is required upon app startup. Or else the packaged app will not recognize the mock server at all (https://stackoverflow.com/a/46608130)
1 parent 002d09e commit 37ee5ab

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

main.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ app.on('ready', () => {
205205
createWindow();
206206
if (!isDev) {
207207
/**
208-
* Note: Even though Express is not used for the duration of the block, this
209-
* is crucial code, and while VS Code will flag it as not being used, it
210-
* should not be removed. Express server is used in production mode as there
211-
* is no dev server.
208+
* Note: Even though Express and mock server is not used for the duration of the block,
209+
* this is crucial code, and while VS Code will flag it as not being used, it
210+
* should not be removed. The servers must be required upon app startup (especially in
211+
* packaged versions) or else the packaged app would not recognize the servers at all.
212212
*/
213213
const express = require('./src/server/server');
214+
const mockServer = require('./src/server/mockServer.js');
214215
autoUpdater.checkForUpdates();
215216
}
216217
});
@@ -420,12 +421,6 @@ ipcMain.on('import-proto', (event) => {
420421
}
421422
importedProto = file;
422423
protoParserFunc(importedProto).then((protoObj) => {
423-
// console.log(
424-
// "finished with logic. about to send importedProto : ",
425-
// importedProto,
426-
// " and protoObj : ",
427-
// protoObj
428-
// );
429424
mainWindow.webContents.send('proto-info', importedProto, protoObj);
430425
});
431426
});
@@ -492,11 +487,11 @@ ipcMain.on('openapiParserFunc-request', (event, data) => {
492487
});
493488

494489
//======================= MOCK SERVER =======================//
495-
const { spawn } = require('child_process');
490+
const { fork } = require('child_process');
496491

497-
// starts the mock server by spawning a Node child process
492+
// starts the mock server by forking a Node child process
498493
ipcMain.on('start-mock-server', () => {
499-
mockServerProcess = spawn('node', ['./src/server/mockServer.js']);
494+
mockServerProcess = fork('node', ['./src/server/mockServer.js']);
500495
mockServerProcess.on('error', (err) => {
501496
console.log('Error starting mock server', err);
502497
});

0 commit comments

Comments
 (0)