Пример #1
53
const http = require('http');
const express = require('express');
const unblocker = require('unblocker');

const userAgent = require('./user-agent.js');

const app = express();

app.use(unblocker({
  requestMiddleware: [
    userAgent('my-cool-user-agent/1.0'),
  ]
}));

app.get('/', (req, res) => res.end('Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy.'));

app.listen(8080);

console.log('app listening on port 8080. Test at http://localhost:8080/proxy/https://duckduckgo.com/?q=what%27s+my+user+agent&atb=v130-1ei&ia=answer')
Пример #2
22
var http = require('http');
var Unblocker = require('unblocker');


var unblocker = Unblocker({});

http.createServer(function(req, res) {
    // first let unblocker try to handle the requests
    unblocker(req, res, function(err) {
        // this callback will be fired for any request that unblocker does not serve
        var headers = {'content-type': 'text/plain'};
        if (err) {
            res.writeHead(500, headers);
            return res.end(err.stack || err);
        }
        if (req.url == '/') {
            res.writeHead(200, headers);
            return res.end('Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy.');
        } else {
            res.writeHead(404, headers);
            return res.end('Error 404: file not found.');
        }
    });
}).listen(8080);

console.log('proxy server live at http://localhost:8080/')
Пример #3
0
            }
        }));
    }
}

var unblockerConfig = {
    prefix: '/proxy/',
    responseMiddleware: [
        googleAnalyticsMiddleware
    ]
};



// this line must appear before any express.static calls (or anything else that sends responses)
app.use(unblocker(unblockerConfig));

// serve up static files *after* the proxy is run
app.use('/', express.static(__dirname + '/public'));

// this is for users who's form actually submitted due to JS being disabled or whatever
app.get("/no-js", function(req, res) {
    // grab the "url" parameter from the querystring
    var site = querystring.parse(url.parse(req.url).query).url;
    // and redirect the user to /proxy/url
    res.redirect(unblockerConfig.prefix + site);
});

// for compatibility with gatlin and other servers, export the app rather than passing it directly to http.createServer
module.exports = app;