本地Node.js应用试图向本地Rails应用发出请求

时间:2018-09-05 20:38:53

标签: ruby-on-rails node.js axios

我有一个Nodejs应用程序在端口8000上本地运行。我有一个Rails应用程序在3003上本地运行。rails应用程序具有该节点应用程序试图向其发送数据的api端点。但是,调用时永远不会触摸api /服务器。我可以从邮递员那里弯腰并卷曲。我打开了一个不同的Rails应用程序,并指向该应用程序(在3000上)的调用,该应用程序至少显示请求通过并返回了404。我将发布nodejs代码和错误。

axios({
    method: 'post',
    url: initData.respondUrl,
    data: {
        crawl_id: initData.crawlID
    }
}).catch(function (error) {
    // handle error
    console.log(error);
});

错误:

{ Error: connect ECONNREFUSED 127.0.0.1:3003
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1158:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3003,
  config:
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     headers:
      { Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/json;charset=utf-8',
        'User-Agent': 'axios/0.18.0',
        'Content-Length': 39 },
     method: 'post',
     url: 'http://localhost:3003/api/v1/crawls/rover_page',
     data: '{"crawl_id":"5b900d8170b5a64f43fd6962"}' },
  request:
   Writable {
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        emitClose: true,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     _events:
      { response: [Function: handleResponse],
        error: [Function: handleRequestError] },
     _eventsCount: 2,
     _maxListeners: undefined,
     _options:
      { protocol: 'http:',
        maxRedirects: 21,
        maxBodyLength: 10485760,
        path: '/api/v1/crawls/rover_page',
        method: 'post',
        headers: [Object],
        agent: undefined,
        auth: undefined,
        hostname: 'localhost',
        port: '3003',
        nativeProtocols: [Object],
        pathname: '/api/v1/crawls/rover_page' },
     _redirectCount: 0,
     _redirects: [],
     _requestBodyLength: 39,
     _requestBodyBuffers: [ [Object] ],
     _onNativeResponse: [Function],
     _currentRequest:
      ClientRequest {
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: false,
        _headerSent: true,
        socket: [Socket],
        connection: [Socket],
        _header:
         'POST /api/v1/crawls/rover_page HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json;charset=utf-8\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 39\r\nHost: localhost:3003\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/api/v1/crawls/rover_page',
        _ended: false,
        res: null,
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Circular],
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] },
     _currentUrl: 'http://localhost:3003/api/v1/crawls/rover_page' },
  response: undefined }

0 个答案:

没有答案