Express4做web服务器,想与Tomcat构建的服务器进行通信,使用的是node-http-proxy进行代理请求java中的json数据,但是请求时间一直在21s左右,想请教一个各位高手要,小弟刚开始使用nodejs,多谢指教!
var express = require(‘express’); var router = express.Router(); var http = require(‘http’); var httpProxy = require(‘http-proxy’);
//新建一个代理Proxy server 对象 var proxy = httpProxy.createProxyServer({}); //代理捕获异常 proxy.on(‘error’, function (err, req, res) { res.writeHead(500, { ‘Content-Type’: ‘text/plain’ });
res.end('Something went wrong,And we are reporting a custom error me');
});
//发生代理之前的修订 proxy.on(‘proxyReq’, function (proxyReq, req, res, options) { console.log("-----proxyReq--------"); });
/* user login action. */ router.post(’/gcl/vri/versionScan’, function (req, res, next) { proxy.web(req, res, {target: ‘http://192.168.11.150:8161’}); console.log("----/gcl/vri/versionScan–"); });