I have an application running Express, and I am trying to distribute it using electron.
Running electron in debug with this:
/path/to/electron/Electron.app/Contents/MacOS/Electron path-to-my-app
My application runs perfectly fine. Express fires up its server and everything works -- the main window opens correctly using mainWindow.loadUrl('http://localhost:3000/');
When I follow the distribution tutorial (linked before) I copy my application resources to:
/path/to/electron/Electron.app/Contents/Resources/app
But now when I run Electron.app, I see Cannot GET /
in the main window... but I have no idea why.
Any ideas?
My only thought is that process.cwd()
is not correctly helping me define the document root here:
//configure Express to default web requests to /workspace/ folder
expressApp.use(express.static(process.cwd() + '/workspace'));
But if that's the case, I don't know how to get around it.
You can run your Express app very easily inside your Electron app. All you need to do is to: place all the files of your Express app inside a new app folder in your_electron_app\resources\app.
Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. By embedding Chromium and Node. js into a single binary file, Electron allows you to create cross-platform apps that work on Windows, macOS, and Linux with a single JavaScript codebase.
It turns out that express
for some reason didn't like my document root mapping.
Rather than using:
//configure Express to default web requests to /workspace/ folder
expressApp.use(express.static(process.cwd() + '/workspace'));
I instead use this:
expressApp.use(express.static(path.join(__dirname, 'workspace')));
Don't use process.cwd
, use process.resourcesPath
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With