Simple Proxy Server with NodeJs

2019-04-11 00:34发布

Currently I have got a simple proxy set up with Apache:

    ProxyPass /ext/ https://ext.a-nice-url.at/
    ProxyPassReverse /ext/ https://ext.a-nice-url.at

It is working fine, but in order to make it easier for others to install I was thinking to make a little server in nodejs. This Server will just be used for developers and testers, so it must not be very huge.

I was already searching on google a bit and found http-proxy, but I am not sure how to use that properly. Any suggestions how I can make that?

标签: node.js proxy
1条回答
看我几分像从前
2楼-- · 2019-04-11 01:11

I got it working with a simple express application as you can see below:

var express = require('express');
var request = require('request');

var app = express();


app.use('/ext/', function(req, res) {

    var url = 'https://ext.a-nice-url.at/' + req.url;
    var options = {
        url: url,
        rejectUnauthorized: false
    }
    req.pipe(request(url)).pipe(res);
});
查看更多
登录 后发表回答