title: My Web application gives CORS error after adding HTTPS using Let's Encrypt
body: <p>This is my application: <a href="https://cfslpro.com/student_portal/" rel="nofollow noreferrer">https://cfslpro.com/student_portal/</a>. Front end is done by AngularJS and back end is done by Node.JS. Hosted in Apache server. (Digital ocean Linux 16.04).</p>
  
  <p>You can try logging in; the username is chanu and the password is 123456.
  Before adding SSL using Let's Encrypt, this application worked well.
  Now I'm getting this error : </p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="https://165.227.121.28:7000/api/user_manage/login" rel="nofollow noreferrer">https://165.227.121.28:7000/api/user_manage/login</a>. (Reason: CORS request did not succeed).</p>
  </blockquote>
  
  <p>But you can run this URL without HTTPS on browser and it's working :</p>
  
  <blockquote>
    <p><a href="http://165.227.121.28:7000/api/user_manage/login" rel="nofollow noreferrer">http://165.227.121.28:7000/api/user_manage/login</a></p>
  </blockquote>
  
  <p>Now I will show you some important sections in my Node.Js server code : </p>
  
  <p>This is how I'm adding CORS plugin. </p>
  
  <pre><code>var cors = require('cors');
  var app = express();
  app.use(cors());
  </code></pre>
  
  <p>And this is how I create HTTP server :</p>
  
  <pre><code>app.listen(config.port, function (err) {
      if (err) {
          console.log(err);
     } else {
          console.log("localhost:7000");
      }
  });
  </code></pre>
  
  <p>i'm creating a HTTP normal server here.</p>
  
  <p>And this is how I'm calling login end point from my front end. </p>
  
  <blockquote>
    <p><a href="https://165.227.121.28:7000/api/user_manage/login" rel="nofollow noreferrer">https://165.227.121.28:7000/api/user_manage/login</a></p>
  </blockquote>
  
  <p>If I use this without HTTPS, I'm getting an error about <code>content blocked</code> because I can't call HTTP request from HTTPS environment. This is where I get CORS error.</p>
  
  <p>This is my <code>/etc/apache2/sites-available/cfslpro.com.conf</code> file : </p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  
          &lt;Directory /var/www/cfslpro.com/public_html&gt;
                  Options Indexes FollowSymLinks MultiViews
  
          &lt;/Directory&gt;
  
          ServerAdmin webmaster@localhost
          ServerName cfslpro.com
          ServerAlias www.cfslpro.com
          DocumentRoot /var/www/cfslpro.com/public_html
  
          ProxyRequests on
          ProxyPass http://165.227.121.28:7000/api/user_manage/login https://localhost:7000/api/user_manage/login
  
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          # It is also possible to configure the loglevel for particular
          # modules, e.g.
          #LogLevel info ssl:warn
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I think my reverse proxy configuration is wrong. I'm new to this proxy configuration and i followed some online examples. I followed this example too : <a href="http://www.codingtricks.biz/run-nodejs-application-apache/" rel="nofollow noreferrer">http://www.codingtricks.biz/run-nodejs-application-apache/</a></p>
  
  <p>This is my .htaccess file :</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
    Header add Access-Control-Allow-Headers: "Content-Type"
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Why is this CORS giving me these errors and issues? I'm someone who is trying to fix and learn.</p>