安裝 cors-anywhere "https" 看全部


如果需要能跑https cors,則要利用letsencrypt-auto產生SSL key
./letsencrypt-auto certonly -d cors.example.com --manual --preferred-challenges dns
#vi cors_anywhere_https.js
加入以下內容
var host = process.env.HOST || '0.0.0.0';
var port = process.env.PORT || 8080;
var fs = require('fs');
var originBlacklist = parseEnvList(process.env.CORSANYWHERE_BLACKLIST);
var originWhitelist = parseEnvList(process.env.CORSANYWHERE_WHITELIST);
function parseEnvList(env) {
  if (!env) {
    return [];
  }
  return env.split(',');
}
var checkRateLimit = require('./lib/rate-limit')(process.env.CORSANYWHERE_RATELIMIT);
var cors_proxy = require('./lib/cors-anywhere');
cors_proxy.createServer({
    httpsOptions: {
        key: fs.readFileSync('/etc/letsencrypt/live/cors.example.com/privkey.pem'),
        cert: fs.readFileSync('/etc/letsencrypt/live/cors.example.com/fullchain.pem')
    },
}).listen(port, host, function() {
  console.log('Running CORS Anywhere on ' + host + ':' + port);
});

CentOS - Run as Service
#npm install pm2@latest -g
#npm install
#pm2 start cors_anywhere_https.js
#pm2 show cors_anywhere_https
#pm2 startup systemd


Reference:
How to setup for https
https://github.com/Rob--W/cors-anywhere/issues/74
https://serverfault.com/question ... hallenge-validation
https://www.digitalocean.com/com ... duction-on-centos-7