-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathproxy.js
35 lines (31 loc) · 919 Bytes
/
proxy.js
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
33
34
35
// HTTP proxy module.
const http = require("http");
// eslint-disable-next-line node/no-unpublished-require
const httpProxy = require("http-proxy");
// Authentication module.
const auth = require("../src/http-auth");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd", // gevorg:gpass, Sarah:testpass
proxy: true
});
// Create your proxy server.
const proxy = httpProxy.createProxyServer({});
http
.createServer(
basic.check((req, res) => {
proxy.web(req, res, { target: "http://127.0.0.1:1338" });
})
)
.listen(1337);
// Create your target server.
http
.createServer((req, res) => {
res.end("Request successfully proxied!");
})
.listen(1338, () => {
// Log URL.
console.log("Server running at http://127.0.0.1:1338/");
});
// You can test proxy authentication using curl.
// $ curl -x 127.0.0.1:1337 127.0.0.1:1337 -U gevorg