forked from Ryan-Hu-233/jsDelivr_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
32 lines (27 loc) · 964 Bytes
/
main.js
File metadata and controls
32 lines (27 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var http = require('http'),
httpProxy = require('http-proxy');
// Create a proxy server with custom application logic
var proxy = httpProxy.createProxyServer({ secure: false });
// Modify Referer and Host header when proxing requests
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('Referer', 'https://hub.docker.com');
proxyReq.setHeader('Host', 'registry-1.docker.io');
});
// Catch errors
proxy.on('error', function (err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Something went wrong. And we are reporting a custom error message.');
console.log(err, req, res);
});
var server = http.createServer(function(req, res) {
// Handle request with proxy
//console.log(req.rawHeaders);
proxy.web(req, res, {
target: 'https://registry-1.docker.io'
});
});
const PORT = process.env.PORT || 3002;
console.log("listening on port " + PORT.toString())
server.listen(PORT);