Proxy mit nodejs

Ich entwickeln eine webapp, gegen eine api. Da die api läuft nicht auf meinem lokalen system, muss ich proxy die Anfrage, damit ich nicht in die cross-domain-Probleme. Gibt es einen einfachen Weg, dies zu tun, so dass meine index.html senden von lokalen und alle anderen GET, POST, PUT, DELETE-Anfrage gehen Sie zu xyz.net/apiEndPoint.

Edit:

dies ist meine erste Lösung, aber hat nicht funktioniert

var express = require('express'),
    app = express.createServer(),
    httpProxy = require('http-proxy');


app.use(express.bodyParser());
app.listen(process.env.PORT || 1235);

var proxy = new httpProxy.RoutingProxy();

app.get('/', function(req, res) {
    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) {
    proxy.proxyRequest(req, res, {
        host: 'http://apiUrl',
        port: 80
    });

});

Wird es dienen die index -, js -, css-Dateien, aber nicht die route, den rest auf der externen api. Dies ist die Fehlermeldung die ich bekommen habe:

An error has occurred: {"stack":"Error: ENOTFOUND, Domain name not found\n    at IOWatcher.callback (dns.js:74:15)","message":"ENOTFOUND, Domain name not found","errno":4,"code":"ENOTFOUND"}
Schreibe einen Kommentar