title: Getting Apache to allow access to Express API over HTTPS
body: <p>My website (<a href="https://www.tjbrackett.com/contact" rel="nofollow noreferrer">https://www.tjbrackett.com/contact</a>), which is on Apache, cannot access my Express app that is on the same server over HTTPS. Before I added an SSL certificate to the site, the setup ran perfectly. When I revert the SSL cert, it works again. The error I'm receiving on the front-end is ERR_CERT_AUTHORITY_INVALID.</p>
  
  <p>I've tried setting up a proxy/reverse proxy. I'm not sure if I set them up correctly. I've done a self-signed SSL cert on the Express app. I've tried to serve the Express app on top of the HTTPS domain.</p>
  
  <p>HTTPS Apache mysite.conf</p>
  
  <pre><code>&lt;IfModule mod_ssl.c&gt;
  &lt;VirtualHost *:443&gt;
          ServerName www.tjbrackett.com
          ServerAdmin tj@brackett.dev
          ServerAlias tjbrackett.com
          DirectoryIndex index.html
          DocumentRoot /var/www/tjbrackett.com
  
          &lt;Directory /var/www/tjbrackett.com&gt;
                      order allow,deny
                      allow from all
  
                      RewriteEngine on
  
                      RewriteCond %{REQUEST_FILENAME} -s [OR]
                      RewriteCond %{REQUEST_FILENAME} -l [OR]
                      RewriteCond %{REQUEST_FILENAME} -d
                      RewriteRule ^.*$ - [NC,L]
                      RewriteRule ^(.*) /index.html [NC,L]
  
          &lt;/Directory&gt;
  
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  
  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/www.tjbrackett.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/www.tjbrackett.com/privkey.pem
  
  ProxyRequests On
  ProxyPass /contact https://www.tjbrackett.com:8443/
  ProxyPassReverse /contact https://www.tjbrackett.com:8443/
  
  &lt;/VirtualHost&gt;
  
  </code></pre>
  
  <p>Express app</p>
  
  <pre><code>const nodemailer = require('nodemailer');
  const express = require('express');
  const bodyParser = require('body-parser');
  const fs = require('fs');
  const http = require('http');
  const https = require('https');
  const app = express();
  
  const options = {
      key: fs.readFileSync(__dirname + '/key.pem'),
      cert: fs.readFileSync(__dirname + '/cert.pem')
  }
  app.use((req, res, next) =&gt; {
      res.header('Access-Control-Allow-Origin', "*");
      res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
      next();
  });
  
  
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(express.json());
  
  app.post('/', (req, res) =&gt; {
      let name = req.body.name;
      let email = req.body.email;
      let subject = req.body.subject;
      let message = req.body.message;
      let mailOptions = "";
      console.log(req.body);
      console.log(req.hostname);
  
      let transporter = nodemailer.createTransport({
          service: 'gmail',
          secure: true,
          auth: {
              user: 'myEmail@bot.com',
              pass: 'jsfoffamlhqzfqnu'
          },
          tls: {
              rejectUnauthorized: false
          }
      });
      if (req.hostname === "www.tjbrackett.com"){
          mailOptions = {
              from: email,
              to: 'myEmail@gmail.com',
              subject: subject,
              text: message + "\nName: " + name + "\nEmail: " + email,
          };
      } else {
          mailOptions = {
              from: email,
              to: 'anotherEmail@gmail.com',
              subject: subject,
              text: message + "\nName: " + name + "\nEmail: " + email,
          }
      }
  
      transporter.sendMail(mailOptions, (error, info) =&gt; {
          if (error) {
              console.log(error);
          } else {
              console.log('Email sent: ' + info.response);
          }
      });
  
      res.send(req.body);
  })
  
  http.createServer(app).listen(8888, () =&gt; {
      console.log("Server started on port 8888");
  });
  https.createServer(options, app).listen(8443, () =&gt; {
      console.log("Server started on port 8443");
  });
  
  </code></pre>
  
  <p>React Fetch</p>
  
  <pre><code>fetch("https://www.tjbrackett.com:8443", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
      name: this.state.name,
      email: this.state.email,
      message: this.state.message
  }) 
  </code></pre>
  
  <p>I've very new to Apache/web servers so at this point I just don't know enough to research the problem. Any suggestions are greatly appreciated. Thanks!</p>