Nuxtjs bad request api 400 axios error production and dev good

徘徊边缘 提交于 2019-12-22 01:45:27

问题


I have a problem that I can not solve for the production my api does not work on the front end, when I directly test the API it works. I do not understand, locally it works perfectly, in production it has a problem.

MY SCRIPT

My page index.js

async asyncData({ store }) {
    const posts = await store.dispatch("post/fetchPostAll");
    return { posts };
},

My page store.js

async fetchPostAll({ commit }) {
    try {
        return await this.$axios.$get('/api/post');
    } catch (e) {
        commit('setError', e, {
            root: true
        });
        throw e;
    }
},

Nuxt config

axios: {
    debug: true,
    baseURL: process.env.BASE_URL || 'http://localhost:8000/nodejsconfig'
},

Request Bad 400

Making request to /api/post
 [Axios] Response error: { Error: Request failed with status code 400
     at createError (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/core/createError.js:16:15)
     at settle (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/core/settle.js:17:12)
     at IncomingMessage.handleStreamEnd (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/adapters/http.js:237:11)
     at IncomingMessage.emit (events.js:203:15)
     at IncomingMessage.EventEmitter.emit (domain.js:448:20)
     at endReadableNT (_stream_readable.js:1143:12)
     at process._tickCallback (internal/process/next_tick.js:63:19)
   config:
    { url: 'https://rembylock/nodejsconfig/api/post',
      method: 'get',
      headers:
       { Accept: 'application/json, text/plain, */*',
         connection: 'close',
         'user-agent':
          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
         'sec-fetch-user': '?1',
         'accept-encoding': 'gzip, deflate',
         'sec-fetch-site': 'none',
         'sec-fetch-mode': 'navigate',
         'accept-language': 'fr-FR,fr;q=0.9',
         cookie:
          'jwt-token="dfgdgdE556a5354eezrezrdXdfsdfsg"',
         'x-https': '1',
         'upgrade-insecure-requests': '1',
         'x-forwarded-proto': 'https',
         '!~passenger-proto': 'https',
         'x-forwarded-for': '26.59.188.10',
         '!~passenger-client-address': '26.59.188.10',
         '!~passenger-envvars':
          'VU5JUVVFX0lEAFhlWHd1QWFMOHc1aFpJadfgdgsdEZ25ER3er0zffd010==' },
      baseURL: 'https://rembylock/nodejsconfig',
      transformRequest: [ [Function: transformRequest] ],
      transformResponse: [ [Function: transformResponse] ],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      validateStatus: [Function: validateStatus],
      data: undefined },

Axios Error:

      data:
       'A secure header was provided, but no security password was provided' },
   isAxiosError: true,
   toJSON: [Function] }
 (node:8710) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
     at createError (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/core/createError.js:16:15)
     at settle (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/core/settle.js:17:12)
     at IncomingMessage.handleStreamEnd (/path/myla/nodevenv/nodejsconfig/10/lib/node_modules/axios/lib/adapters/http.js:237:11)
     at IncomingMessage.emit (events.js:203:15)
     at IncomingMessage.EventEmitter.emit (domain.js:448:20)
     at endReadableNT (_stream_readable.js:1143:12)
     at process._tickCallback (internal/process/next_tick.js:63:19)
 (node:8710) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 12)

Edit: sorry, log fixed

来源:https://stackoverflow.com/questions/59147227/nuxtjs-bad-request-api-400-axios-error-production-and-dev-good

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!