No response using express proxy route

后端 未结 5 907
执念已碎
执念已碎 2020-12-07 08:55

I\'ve written a small proxy with nodejs, express and htt-proxy. It works well for serving local files but fails when it comes to proxy to external api:

var e         


        
5条回答
  •  我在风中等你
    2020-12-07 09:51

    Maybe I use http-proxy in a wrong way. Using restler does what I want:

    var express = require('express'),
        app = express.createServer(),
        restler = require('restler');
    
    
    app.use(express.bodyParser());
    app.listen( 1234);
    
    
    
    app.get('/', function(req, res) {
        console.log(__dirname + '/index.html')
        res.sendfile(__dirname + '/index.html');
    });
    app.get('/js/*', function(req, res) {
        res.sendfile(__dirname + req.url);
    });
    app.get('/css/*', function(req, res) {
        res.sendfile(__dirname + req.url);
    });
    
    
    app.all('/*', function(req, res) {
    
        restler.get('http://myUrl.com:80/app_test.php/api' + req.url, {
    
            }).on('complete', function (data) {
                    console.log(data)
                   res.json(data)
                });
    
    });
    

提交回复
热议问题