内部NuxtJS API调用导致499错误。外部没问题

时间:2019-07-08 13:21:58

标签: javascript nuxt.js nuxt

我正在尝试使用Nuxt的serverMiddleware将某些数据作为JSON数组提取。当我在浏览器中点击此端点时,它会做出响应。当我尝试从nuxtjs视图调用它时,将导致错误。

我尝试了外部API,它们似乎都能正常工作。

import fetch from 'isomorphic-fetch';
export default {
  async asyncData () {
    //const response = await axios.get('http://archiveapi.eu-west-1.elasticbeanstalk.com/records')
    let records = await fetch('https://e2b1d1c39ae942c29ebbcb77ffeb3c83.vfs.cloud9.eu-west-1.amazonaws.com/api/test');
    console.log(records)
    return { files: records }
  },
}

我希望有一个带有数据的对象,但是我得到了。

Body {                                                                                                        13:17:30
  url: 'https://e2b1d1c39ae942c29ebbcb77ffeb3c83.vfs.cloud9.eu-west-1.amazonaws.com/api/test',
  status: 499,
  statusText: 'unknown',
  headers: 
   Headers {
     _headers: 
      { date: [Array],
        'content-type': [Array],
        'transfer-encoding': [Array],
        connection: [Array],
        'set-cookie': [Array],
        'cache-control': [Array] } },
  ok: false,
  body: 
   PassThrough {
     _readableState: 
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 3015,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: true,
        sync: false,
        needReadable: true,
        emittedReadable: true,
        readableListening: false,
        resumeScheduled: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     domain: null,
     _events: 
      { end: [Object],
        prefinish: [Function: prefinish],
        unpipe: [Function: onunpipe],
        drain: [Function],
        error: [Function: onerror],
        close: [Object],
        finish: [Object] },
     _eventsCount: 7,
     _maxListeners: undefined,
     _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: false,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: true,
     _transformState: 
      { afterTransform: [Function: bound afterTransform],
        needTransform: true,
        transforming: false,
        writecb: null,
        writechunk: null,
        writeencoding: 'buffer' } },
  bodyUsed: false,
  size: 0,
  timeout: 0,
  _raw: [],
  _abort: false }

0 个答案:

没有答案