Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http');
- const net = require('net');
- const {URL} = require('url');
- const url = require('url');
- http.createServer((req, res)=>{
- let body = 'hello world\n';
- res.writeHead(+url.parse(req.url).pathname.substr(1)||200,
- {'Content-Length': body.length});
- res.end(body);
- }).listen(80);
- for (let proxy_port=12001; proxy_port<=12010; proxy_port++)
- {
- const proxy = http.createServer((client_req, client_res)=>{
- var options = {
- hostname: client_req.headers.host,
- port: 80,
- path: client_req.url,
- method: client_req.method,
- headers: client_req.headers
- };
- let proxied = http.request(options, res=>{
- client_res.writeHead(res.statusCode, res.headers);
- res.pipe(client_res, {end: true});
- });
- client_req.pipe(proxied, {end: true});
- });
- proxy.listen(proxy_port, '127.0.0.1', ()=>{
- console.log('Listen '+proxy_port);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement