Skip to content

Instantly share code, notes, and snippets.

@Xexuline
Forked from mizzy/node-simple-proxy.js
Created October 9, 2018 19:18
Show Gist options
  • Select an option

  • Save Xexuline/2e47ca40ee2a0df5914d9312d77410dd to your computer and use it in GitHub Desktop.

Select an option

Save Xexuline/2e47ca40ee2a0df5914d9312d77410dd to your computer and use it in GitHub Desktop.

Revisions

  1. @mizzy mizzy revised this gist Nov 6, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion node-simple-proxy.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,6 @@ var proxy = http.createServer(function(req, res) {
    var backend_req = http.request(options, function(backend_res) {
    res.writeHead(backend_res.statusCode, backend_res.headers);
    backend_res.on('data', function(chunk) {
    console.log(chunk);
    res.write(chunk);
    });
    backend_res.on('end', function() {
  2. @mizzy mizzy revised this gist Nov 6, 2011. No changes.
  3. @mizzy mizzy created this gist Nov 6, 2011.
    35 changes: 35 additions & 0 deletions node-simple-proxy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    var http = require('http');
    var url = require('url');

    var proxy = http.createServer(function(req, res) {
    var request = url.parse(req.url);
    options = {
    host: request.hostname,
    port: request.port || 80,
    path: request.path,
    method: req.method,
    headers: req.headers,
    };

    var backend_req = http.request(options, function(backend_res) {
    res.writeHead(backend_res.statusCode, backend_res.headers);
    backend_res.on('data', function(chunk) {
    console.log(chunk);
    res.write(chunk);
    });
    backend_res.on('end', function() {
    res.end();
    });
    });

    req.on('data', function(chunk) {
    backend_req.write(chunk);
    });

    req.on('end', function() {
    backend_req.end();
    });

    });

    proxy.listen(8000);