I have a node.js app that serve static files (html, js, css). Among the static files, some ajax request are done (with /TEST in the request). I need those request to be proxied to another server running on localhost:213445. The static pages are correctly displayed but when it comes to proxied request it hangs forever…
My code is:
var express = require("express");
var httpProxy = require('http-proxy');
var fs = require('fs');
// Create https server
var app = express.createServer({
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
});
// Handle static files
app.use(express.static(__dirname + '/public'));
// Proxy request
app.all('/TEST/*',function(req, res){
// Remove '/TEST' part from query string
req.url = '/' + req.url.split('/').slice(2).join('/');
// Create proxy
var proxy = new httpProxy.HttpProxy();
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 21345,
enableXForwarded: false,
buffer: proxy.buffer(req)
});
});
// Run application
app.listen(10443);
I have the same issue. If you comment out the
you will see that the the proxy works.
Not sure how to fix it if express.static is used
Marak Squires responded to the bug report!