title: Serve static files with express from within electron-forge app
body: <p>I've written a quick <a href="https://www.electronforge.io/" rel="nofollow noreferrer">Electron Forge</a> app that simply runs an express webserver that serves static files locally.  I prefer this to running a node process directly for usability.</p>
  
  <p><strong>main.js</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>import { app, BrowserWindow } from 'electron';
  import express from 'express';
  
  const exApp = express();
  exApp.use(express.static('web-app'));
  exApp.listen(3333);
  
  let mainWindow;
  
  const createWindow = () =&gt; {
    // Create the browser window.
    mainWindow = new BrowserWindow({
    // ...
    });
  
    // ...
  };
  
  // ...
  </code></pre>
  
  <p>I use the <a href="https://webpack.js.org/plugins/copy-webpack-plugin/" rel="nofollow noreferrer">CopyWebpackPlugin</a> to copy the files I need to serve into the <code>.webpack/main/web-app/</code> directory.</p>
  
  <p><strong>webpack.main.config.js</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports = {
    /**
     * This is the main entry point for your application, it's the first file
     * that runs in the main process.
     */
    entry: './src/main.js',
    // Put your normal webpack config below here
    module: {
      rules: require('./webpack.rules'),
    },
    plugins: [
      new CopyPlugin([
        { from: path.resolve(__dirname, 'web-app'), to: 'web-app' }
      ]),
    ]
  };
  </code></pre>
  
  <p>This works perfectly in development (via <code>yarn start</code>).</p>
  
  <p>When I try to run <code>yarn make</code>, it successfully builds the app and generates a runnable exe, but trying to access <code>http://localhost:3333/</code> after running the app, results in a <code>Cannot GET /</code> 404 message.</p>
  
  <p>Any idea what I'm doing wrong?</p>