title: Express NodeJS Routing Error text/html is not text/event-stream
body: <p>I have a simple Node Express server setup that serves an html file with a bundle.js. Whenever I try to add a route that catches all routes and redirects to the homepage, I get an error in the console when I open an unmapped route saying </p>
  
  <p><strong>"EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection."</strong></p>
  
  <p>I'm not exactly sure what this means, I was also having issues with trying to serve the index.html (Issues with the path for the file) so it's possible that might have something to do with this. I'm trying to serve the Index.html inside the build folder.</p>
  
  <p>Project Structure:<br>
  <a href="https://i.stack.imgur.com/t3SKa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t3SKa.png" alt="enter image description here"></a></p>
  
  <p>Index.js (Server File)</p>
  
  <pre><code>const http = require('http');
  const express = require('express');
  const bodyParser = require('body-parser');
  const path = require('path');
  
  const app = express();
  const server = http.createServer(app);
  
  app.use(bodyParser.json());
  
  app.use(express.static(path.join(__dirname, '.', 'public/build')));
  
  app.get('/', (req, res) =&gt; {
      res.sendFile('index.html', {root: path.join(__dirname, 'public/build')});
      res.end();
  });
  
  app.all('*', (req, res) =&gt; {
      console.log('triggered');
      res.redirect('/');
      res.end();
  });
  
  
  server.listen(3000);
  </code></pre>
  
  <p>Oddly enough, when I go to localhost:3000 It prints "triggered" in the node console and If I remove the "app.all" line of code that catches any other routes, then it doesn't throw this error anymore:</p>
  
  <p><strong>"EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection."</strong></p>
  
  <p>However, If I remove the line of code that catches routes, I get the error "cannot GET /routename" as expected. </p>
  
  <p>Index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;title&gt;project&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="root"&gt;&lt;/div&gt;
  &lt;script type="text/javascript" src="bundle.js"&gt;&lt;/script&gt;&lt;/body&gt;
  
  &lt;/html&gt;
  
  </code></pre>
  
  <p>Content being rendered in the Index.html file</p>
  
  <pre><code>import React from 'react';
  import './styles/index.css';
  
  const App = () =&gt; {
      return (
          &lt;div&gt;
              &lt;h1&gt;Home Page&lt;/h1&gt;
              &lt;button onClick={null}&gt;Click Me&lt;/button&gt;
          &lt;/div&gt;
      );
  };
  
  export default App;
  </code></pre>
  
  <p>Index.js (Client side)</p>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  import {Provider} from 'react-redux';
  import App from './App';
  import store from './redux/store';
  
  require('webpack-hot-middleware/client');
  
  ReactDOM.render(
      &lt;Provider store={store}&gt;
          &lt;App/&gt;
      &lt;/Provider&gt;
      , document.getElementById('root')
  );
  
  
  </code></pre>