title: Error getting SSE messages, Angular frontend, Node backend
body: <p>I'm using SSE to send simple messages from a Node backend to an Angular app. So far, it's been working flawlessly, but today I realized that it's not working anymore and I can't find the reason.</p>
  
  <p>This is the relevant code:</p>
  
  <p><strong>NODE</strong></p>
  
  <pre><code>router.get('/stream', function (req, res) {
      [ ... ]
  
      // Send headers for event-stream connection
      res.writeHead(200, {
          'Content-Type': 'text/event-stream',
          'Cache-Control': 'no-cache',
          'Connection': 'keep-alive'
      });
      res.write('\n');
  
      [ ... ]
      // NOTE: This line connects to a Redis server
      subscriber.subscribe(channel);
  
      // In case we encounter an error...print it out to the console
      subscriber.on("error", function (err) {
          logger.debug("Redis Error: " + err);
      });
  
      // When we receive a message from the Redis connection
      subscriber.on("message", function (channel, message) {
          logger.debug('MESSAGE RECEIVED: ' + message);   // This message is printed in the log file
  
          [ ... ]
          // Note: 'msgData' is obtained by parsing the received 'message'
          // Send data to the client
          res.write('data: ' + msgData + "\n\n");
      });
  }
  </code></pre>
  
  <p><strong>Angular app</strong></p>
  
  <pre><code>declare var EventSource : any;
  
  getSSEMessages(): Observable&lt;string&gt; {
      let sseUrl = `${ConfigService.settings.appURL}/stream`;    
  
      return new Observable&lt;string&gt;(obs =&gt; {
          const es = new EventSource(sseUrl, { withCredentials: true });  
  
          // This prints '1' (CONNECTION OPEN)
          console.log('SSE Connection: ', es.readyState);               
  
          // Note: I've also tried 'es.onerror'
          es.addEventListener("error", (error) =&gt; {
              console.log("Error in SSE connection", error);
  
              return false;
          });
  
          // Note: I've also tried 'es.onmessage'
          es.addEventListener("message", (evt : any) =&gt; {
              // Never gets in here
              console.log('SSE Message', evt.data);
  
              obs.next(evt.data);
          });
  
          return () =&gt; es.close();
      });
  }
  </code></pre>
  
  <p>This is how I get the messages when I select the option in the interface:</p>
  
  <pre><code>this.getSSEMessages()
    .subscribe(message =&gt; {
      // SHOW MESSAGE TO THE USER
  });
  </code></pre>
  
  <p>As I said, everything has been working fine for weeks. Today I saw that I wasn't getting any messages and I've been trying to find out the reason without luck.</p>
  
  <p>Any clues on what can be wrong?</p>