Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. const http = require('http');
  2. const net = require('net');
  3. const {URL} = require('url');
  4. const url = require('url');
  5.  
  6. http.createServer((req, res)=>{
  7. let body = 'hello world\n';
  8. res.writeHead(+url.parse(req.url).pathname.substr(1)||200,
  9. {'Content-Length': body.length});
  10. res.end(body);
  11. }).listen(80);
  12.  
  13. for (let proxy_port=12001; proxy_port<=12010; proxy_port++)
  14. {
  15. const proxy = http.createServer((client_req, client_res)=>{
  16. var options = {
  17. hostname: client_req.headers.host,
  18. port: 80,
  19. path: client_req.url,
  20. method: client_req.method,
  21. headers: client_req.headers
  22. };
  23. let proxied = http.request(options, res=>{
  24. client_res.writeHead(res.statusCode, res.headers);
  25. res.pipe(client_res, {end: true});
  26. });
  27. client_req.pipe(proxied, {end: true});
  28. });
  29. proxy.listen(proxy_port, '127.0.0.1', ()=>{
  30. console.log('Listen '+proxy_port);
  31. });
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement