Skip to content

Commit 4170e22

Browse files
author
shiwenzhe
committed
setup reverse cf proxy
1 parent aa0aa4a commit 4170e22

File tree

4 files changed

+161
-3
lines changed

4 files changed

+161
-3
lines changed

config.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"pfx": "https://test-routes-lyart.now.sh/proxy-http/node-webproxy.herokuapp.com",
2+
"pfx1": "https://test-routes-lyart.vercel.app/proxy-https/node-webproxy.herokuapp.com",
33
"local_port": 6668,
4-
"remote_port": 80
4+
"remote_port": 80,
5+
"cfOrigin": "",
6+
"cfip": "",
7+
"cfPort": 8866
58
}

local-cf.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var httpProxy = require('http-proxy');
2+
const http = require('http');
3+
const conf = require('./config.json')
4+
5+
const staticLookup = (ip, v) => (hostname, opts, cb) => cb(null, ip, v || 4);
6+
7+
function encryptUrl(str) {
8+
const a = str.split('').reverse().join('');
9+
return encodeURIComponent(a);
10+
}
11+
12+
const httpAgent = new http.Agent({
13+
keepAlive: true,
14+
keepAliveMsecs: 50 * 1000,
15+
lookup: staticLookup(conf.cfip, 4),
16+
});
17+
18+
const proxy = httpProxy.createProxyServer(); // See (†)
19+
20+
const server = http.createServer(function (req, res) {
21+
const url1 = req.url.replace(/^\//, '')
22+
req.url = '/' + encryptUrl(url1)
23+
24+
proxy.web(req, res, {
25+
target: conf.cfOrigin,
26+
agent: httpAgent,
27+
changeOrigin: true,
28+
toProxy: true,
29+
});
30+
});
31+
32+
server.listen(8866);

package-lock.json

Lines changed: 123 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14+
"http-proxy": "^1.18.1",
1415
"know-your-http-well": "^0.5.0",
1516
"lodash": "^4.17.4",
1617
"node-fetch": "^2.6.0",

0 commit comments

Comments
 (0)