title: CORS Regex in Node Express Server
body: <p>I am creating an <code>express</code> server. This is the snippet. </p>
  
  <pre><code>const app = express();
  app.use(cookieParser()); // mainly used to retrieve and store CSSO tokens
  app.use(bodyParser.json());
  
  app.use(function(req, res, next) {
      res.header("Access-Control-Allow-Origin", "https://the.real.url.com:8081");
      res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
      res.header("Access-Control-Expose-Headers", "Content-Disposition, Content-Type");
      res.header("Access-Control-Allow-Credentials", true);
      next();
  });
  </code></pre>
  
  <p>It is working currently. But I need to replace <code>https://the.real.url.com:8081</code> with <code>regex</code>. 
  First, it can be <code>https</code> or just <code>http</code>. 
  Second, there may or may not be a port. and so forth. </p>
  
  <p>So when I edited it <code>https?://the.real.url.com:8081</code> to allow both <code>http</code> and <code>https</code>. </p>
  
  <p>I get this error 
  <code>The 'Access-Control-Allow-Origin' header contains the invalid value 'https?://the.real.url.com:8081'. Origin 'https://the.real.url.com:8081' is therefore not allowed access.</code></p>
  
  <p>I also tried <code>http(s?)://the.real.url.com:8081</code>, <code>https?://*</code>, and other variations. None of them works. </p>
  
  <p>So I am wondering <code>Regex</code> is not allowed? But the wildcard <code>*</code> works. </p>
  
  <p>Am I doing something wrong? </p>