JDP 發表於 2018-3-19 17:10:23

安裝 cors-anywhere "https"


[*]下載 cors-anywhere:https://github.com/Rob--W/cors-anywhere/releases
[*]CentOS安裝nodejs:yum install nodejs
[*]解壓縮cors-anywhere,node server.js就可以執行 (這樣是只能http,不能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/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-centos-7
頁: [1]
查看完整版本: 安裝 cors-anywhere "https"