CORS Proxy выдает ошибки при отправке запроса через React Front End - PullRequest
0 голосов
/ 29 января 2020

Код ответа для запросов Elasti c API поиска:

Создание клиента

let client = new elasticsearch.Client({
    host: "user:password@localhost:80",
    log: "error"
  });

Создание функции с использованием клиента:

getResponse = () => {
        client
          .search({
              index: 'index-2020-01-29',
              body: {
                "query": {
                    "match": {
                    "host": "myhost.domain.com"
                    }
                }
            }
        },
        function(error, response, status) {
            if (error) {
                const errorMessage = {error};
                console.log({errorMessage});
            }
            else {
                this.setState({results: response.hits.hits});
                console.log(this.state.results);
            }
        });
    }

Мой сервер. js файл, используемый прокси-сервером для избежания ошибки CORS, выглядит следующим образом:

var express = require('express')
var request = require('request')
var cors = require('cors')
var app = express()
app.use(cors())
app.use('/', function(req, res) {
    var url = 'https://' + req.get('host').replace('localhost:80', 'actualhostname:port') + req.url
    req.pipe(request({ qs:req.query, uri:url, json: true })).pipe(res);
  })

app.listen(80, function () {
    console.log('CORS-enabled web server listening on port 80')
    })

Сообщение об ошибке, когда я нажимаю Submit на внешнем интерфейсе, который запрашивает API. Мой сервер. js фактически потерпел крах с этим:

M:\node\react_ui\src>node server.js
CORS-enabled web server listening on port 80
internal/streams/legacy.js:59
      throw er; // Unhandled stream error in pipe.
      ^

Error: connect ECONNREFUSED 127.0.0.1:443
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14)

Ошибка в консольном журнале Chrome:

index.js:1437 ERROR: 2020-01-29T07:23:06Z
  Error: Request error, retrying
  POST http://localhost/index-2020-01-29/_search => Request failed to complete.
      at Log.push../node_modules/elasticsearch/src/lib/log.js.Log.error (http://localhost:8000/static/js/1.chunk.js:137455:56)
      at checkRespForFailure (http://localhost:8000/static/js/1.chunk.js:138368:18)
      at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/static/js/1.chunk.js:136800:7)

xhr.js:81 OPTIONS http://localhost/index-2020-01-29/_search net::ERR_CONNECTION_REFUSED
xhr.js:81 HEAD http://localhost/ net::ERR_CONNECTION_REFUSED
AgentDetailsPage.js:52 
{errorMessage: {…}}
    errorMessage:
        error: NoConnections
            message: "No Living connections"
            stack: "Error: No Living connections?    at sendReqWithConnection (http://localhost:8000/static/js/1.chunk.js:138344:15)?    at next (http://localhost:8000/static/js/1.chunk.js:136419:7)?    at Item.push../node_modules/process/browser.js.Item.run (http://localhost:8000/static/js/1.chunk.js:221293:12)?    at drainQueue (http://localhost:8000/static/js/1.chunk.js:221257:34)"
            __proto__: ErrorAbstract
        __proto__: Object
    __proto__:
        constructor: ƒ Object()
        hasOwnProperty: ƒ hasOwnProperty()
        isPrototypeOf: ƒ isPrototypeOf()
        propertyIsEnumerable: ƒ propertyIsEnumerable()
        toLocaleString: ƒ toLocaleString()
        toString: ƒ toString()
        valueOf: ƒ valueOf()
        __defineGetter__: ƒ __defineGetter__()
        __defineSetter__: ƒ __defineSetter__()
        __lookupGetter__: ƒ __lookupGetter__()
        __lookupSetter__: ƒ __lookupSetter__()
        get __proto__: ƒ __proto__()
        set __proto__: ƒ __proto__()

Может кто-нибудь указать, что я делаю неправильно Вот? Я рад предоставить больше информации, если требуется. Спасибо

...