frankhale / electron-with-express

A simple app that demonstrates spawning an Express app from Electron
MIT License
643 stars 147 forks source link

server is still working after quitting the app #11

Closed baticodes closed 6 years ago

baticodes commented 6 years ago

what about adding something like that?

main.js:

mainWindow.on('close', function() {
    mainWindow.webContents.send('stop-server');
});

index.html:

const {ipcRenderer} = require('electron');
...
ipcRenderer.on('stop-server' , function(event , data){
  node.kill('SIGINT');
});
frankhale commented 6 years ago

Hi, this one must have slipped through the cracks. Thanks for reporting it. The funny thing is I wrote another app that kind of follows this same pattern and I did sort of exactly what you say here. I think the only difference is that instead of hard killing node I stop the Express server gracefully first before I exit the process. I'll get this fixed! Thanks for reporting.

frankhale commented 6 years ago

I haven't forgot about this. Thanks for reporting it!

frankhale commented 6 years ago

I've adopted your method for now. We can do better and use something like Socket.IO to communicate with the server itself (the Express app) and have it gracefully shutdown. This approach would be better especially if we had database connections or were using other resources that needed to be cleaned up on exit. That said, we'll just use your approach for now.

Thank you for submitting this!