title: Why and how this simple node.js proxy works?
body: <p>I have a frontend-only web application on Netlify which has to consume an API on OpenSubtitles.org. Although OpenSubtitles.org enables CORS, <em>sometimes</em> I got preflight errors, so I decided to use a proxy.</p>
  
  <p>I had problems using Netlify's proxy feature, so I decided I will create my own proxy on Heroku, and send my requests from the frontend to there, so these will be proxied to OpenSubtitles.org from a server.</p>
  
  <p>I came up with the following based on the code I found <a href="https://blog.javascripting.com/2015/01/17/dont-hassle-with-cors/" rel="nofollow noreferrer">here</a>:</p>
  
  <pre><code>const express = require('express');
  const request = require('request');
  
  express()
      .use('/', function(req, res) {
          req.pipe(
              request({
                  url: 'http://rest.opensubtitles.org/search' + req.url,
                  headers: {
                      'User-Agent': 'TemporaryUserAgent'
                  }
              })
          ).pipe(res);
      })
      .listen(process.env.PORT || 8000);
  </code></pre>
  
  <p>I thought I deploy this, try it out, then I will enable CORS on it after that. However I've just realized it is working perfectly without doing anything else. How is it possible? Why can I call this from a frontend-only app on a different domain without explicitly enabling CORS?</p>
  
  <p>Also, what if the server crashes, how to handle the errors there?</p>