Elastic search node.js proxy request freezed

时间:2016-08-31 12:13:14

标签: express elasticsearch proxy webpack

i tried to make request to elastic search server (localhost:9200) from my server localhost:8080, but when I'am doing that there is no response from elastic search, code :

var express = require('express');
var router = express.Router();
// var esClient = require('../db/esProvider');
var proxy = require('http-proxy-middleware');

router.use('/:apiKey/_search', proxy({
    target: 'http://127.0.0.1:9200/',
    changeOrigin:true,
    pathRewrite: function (path, req) {
        return path.replace('/api', '')
    },
    onProxyReq: function (proxyReq, req, res) {
      console.log('request')
    },
    onProxyRes: function (proxyRes, req, res) {
        // add new header to response
        console.log('resoponse')
    },
    onError:function(err, req, res){
        console.log(err)
    }
}));

what's wrong with my proxy config, when i try to create proxy server via webpack-dev-server, I receive normal response...

1 个答案:

答案 0 :(得分:0)

哦,对不起,这是身体解析器问题,我在应用正文解析器中间件后发送POST请求,这就是代理服务器向弹性搜索发送无效正文的原因