Activities

orhanmusellim

orhanmusellim posted a new question

axios-module •

F5 Refresh return string problem.

I am using asyncData on the page. Open page axios method works well on Nuxt route. Return the object on the API. However, when you refresh the page, the object data returns as a string. I can't use JSON.parse either.
My asyncData codes ;

async asyncData({params, $axios}) { const productDetail = await $axios.$get('/store/products/getsingle/' + params.slug) return {ilanDetail, productDetail} },

Please help me.

orhanmusellim

orhanmusellim posted a new question

axios-module •

F5 Refresh return string problem.

I am using asyncData on the page. Open page axios method works well on Nuxt route. Return the object on the API. However, when you refresh the page, the object data returns as a string. I can't use JSON.parse either.
My asyncData codes ;

async asyncData({params, $axios}) { const productDetail = await $axios.$get('/store/products/getsingle/' + params.slug) return {ilanDetail, productDetail} },

Please help me.

Mariana-Yui

Mariana-Yui posted a new question

axios-module •

asyncData axios 503

when I use $axios.$get in asyncData,

async asyncData({ $axios }) {
        const { list } = await $axios.$get('http://localhost:3000/api/list')
        return { list }
    }

ubuntu terminal always throw error like:

(node:9628) UnhandledPromiseRejectionWarning: Error: Request failed with status code 503
at IncomingMessage.emit (events.js:228:7)
    at IncomingMessage.EventEmitter.emit (domain.js:475:20)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
(node:9628) 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: 6)
(node:9628) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

but when I use the terminal in the vscode, error disappeared. I'm confused. :(

cfroe

cfroe posted a new question

axios-module •

5.9.x Internet Explorer 11 throwing errors

Using Nuxt Axios module with 5.9.x Internet Explorer 11 is not working anymore throwing errors 'const' is undefined. 5.8.0 is working

cfroe

cfroe posted a new question

axios-module •

5.9.x Internet Explorer 11

Using Nuxt Axios module with 5.9.x Internet Explorer 11 is not working anymore throwing errors 'const' is undefined. 5.8.0 is working

golubvladimir

golubvladimir posted a new bug report

axios-module •

bug Don't work validateStatus ?

Version

v5.9.5

Reproduction link

https://codesandbox.io/s/hardcore-moon-80gu8

Steps to reproduce

Wran get a response with 402 error, my onError function work, but validateStatus in this case is false.

What is expected ?

Wran get a response with 402 error, my onError function work, but validateStatus in this case is false.

What is actually happening?

Work onResponse method

golubvladimir

golubvladimir posted a new question

axios-module •

How to return result to action, if I retry request in onError ?

I have getMenu action with axios.

export const actions = {
  async getMenu({rootState, commit}) {
    try {
      const { auth, lang } = rootState;

      const {items} = await this.$axios.$get(`/api/${ lang.locale }/menu`, {
        headers: {
          'Authorization': `bearer ${auth.token}`,
          'Accept-Language': `${lang.locale}`
        },
      });

      console.log({'getMenu': items});

      if (items) {
        // set items
        commit('setMenu', items);
      }
    } catch (error) {
      console.log({Error: error})
    }
  }
};

In backend on this route, I have middleware authenticate user.
In case of error, I request new token, after I make a new request.

$axios.onError(async (error) => {
    const code = parseInt(error.response && error.response.status);
    const message = error.response && error.response.data && error.response.data.error;

      if (code === 403) {
        await store.dispatch(
          'auth/refreshToken',
          { refreshToken: store.state.auth.refreshToken },
          { root: true }
        );

        const method = error.config.method;
        const url = error.config.url;
        const token = store.state.auth.token;
        const locale = store.state.lang.locale;

        if (method === 'get') {
          return await $axios.$get(url, {
            headers: {
              'Authorization': `bearer ${ token }`,
              'Accept-Language': `${ locale }`
            }
          });
        }
      }

How to return resut to initial action ?

usb248

usb248 posted a new feature request

axios-module •

idea axios cookie

What problem does this feature solve?

Handle cookie jar in order to automatically resend received cookies on every subsequent request (server-side).
Actually, axios doesn't resend cookie received (with set-cookie) by nuxt serverResponse (in a serverMiddleware for example).
It cause many problem in my nuxt app.

I have to do something like this (temporary fix) :

$axios.onResponse((resp) => {
        if(resp.headers['set-cookie'] && process.server){
            try{
                // add header to nuxt's server response
                res.setHeader('Set-Cookie', [ ...resp.headers['set-cookie'] ])
            }catch(e) {}
        }
        return resp
    })

but in some case, set-cookie header is duplicated…

usb248

usb248 posted a new question

axios-module •

Unable to set cookie when process.server is true

I have a serverMiddleware with a cookie parser with an internal API (with express).
// Export the server middleware export default { path: '/api', handler: app }
All work fine client side but when axios request is trigerred server side, axios doesn't add set-cookie. I have to do:
$axios.onResponse((resp) => { if(resp.headers['set-cookie'] && process.server){ try{ res.setHeader('Set-Cookie', [ resp.headers['set-cookie'] ]) }catch(e) {} } return resp })
Why ?

Dean-Christian-Armada

Dean-Christian-Armada posted a new question

axios-module •

Axios Post with request body makes loading not progress properly

I am uncertain if this is a bug but I have a page that is using async fetch. I am calling a particular API with POST method like below

pages/index.vue

<template>
  <div>
  </div>
</template>

<script>

export default {
  async fetch({ $axios, store, context }) {
    try {
      await $axios
        .$post("http://localhost:3000/api/scooby", {
          url:
            "http://localhost:8000/v1/member/banners/?ad_type=1&page=supreme_home"
        })
        .then(res => {
          console.log("It works");
        });;
    } catch (e) {
      console.log("Error: " + e.stack);
    }
  }
};
</script>

What happens is.. The loading is not working properly.. I intentionally made the API response in 2 seconds so I can see the progress bar.. But it behaves something like the progress will be finished in just 0.1 seconds but the request is still ongoing.

TAKE NOTE:

  • If I just made it await $axios.$post("http://localhost:8000/v1/member/banners/?ad_type=1");. The progress is working fine where I just removed the request body.. Also take note that I did not set any configuration but just used the nuxt axios module.

It's been hours where I'm figuring this behaviour out

Dean-Christian-Armada

Dean-Christian-Armada posted a new question

axios-module •

How to set the Client-IP on Nuxt Server side when making a request?

Is there like a setting where this will be automatically enabled? To be specific I want to put the Client IP on X-Real-IP and X-Forwarded-For request headers. It says in in your options that just setting the proxyHeaders true will set the Client Request headers which I think should have included the X-Forwarded-For or X-Client-Ip

mikkokut

mikkokut posted a new feature request

axios-module •

idea Please upgrade to axios 0.19.2 to get rid of XSS bug

What problem does this feature solve?

Get rid of Axios XSS bug introduced in 0.19.1

golubvladimir

golubvladimir posted a new question

axios-module •

How to define different URLs for client and server ?

How to define different URLs for client and server ?

VinuRaj

VinuRaj posted a new question

axios-module •

Requesting URL with 'javascript' keyword throwing XSS error.

It seems any request to urls containing "javascript" keyword (like yourdomain.com/tag/javascript) is throwing XSS error.

It seems to be a bug in axios v0.19.1

original thread- https://github.com/axios/axios/issues/2646

There seems to be fix released for it - https://github.com/axios/axios/releases/tag/v0.19.2

Could there be an urgent release for @nuxtjs/axios to solve this bug.

pSnehanshu

pSnehanshu posted a new question

axios-module •

How to maintain baseURL for axios?

In my nuxt.config.js, i have

module.exports = {
  // other options have been removed

  axios: {
    baseURL: '/api'
  }
}

It works fine when I am using axios in the client side. My url is localhost:3050,
But when I use axios in the server i.e. inside the fetch method, it doesn't work. Instead of requesting https://localhost:3050/api, it requests https://localhost/api.

I think this is trivial, but what's the best way to solve this issue?

mbf5923

mbf5923 posted a new question

axios-module •

axios response on error with code 400

hi
in @nuxtjs/axios if server return data with code 400, error.response will be undefined and error only say "Network Error"
i use latest version of nuxt axios 5.9.3

iabukai

iabukai posted a new question

axios-module •

Proxying from https:// to another https://

hi,
I'm trying to call a simple httprequest from https://localhost:3000 to https://somwhereelse:8181

const STORE_URL = 'https://somewhereelse:8181'

export async function storeData (data) {
  const resp = await axios.get(`${STORE_URL}/store`, { data })
  return resp.key
}

I got cors origin request blocked error due to
```Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://somewhereelse:8181/store. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

As I know I should set it at the remote. In this case  https://somewhereelse:8181/store

If I check it then I can see that is already set and it's accepts */*

curl -v -X OPTIONS 'https://somewhereelse:8181/store' -H "Origin:https://localhost:3000" -H "Access-Control-Request-Method: GET,PUT,POST,HEAD,DELETE"

> OPTIONS /store HTTP/2
> Host: somewherelse:8181
> User-Agent: curl/7.65.3
> Accept: */*
> Origin:https://localhost:3000
> Access-Control-Request-Method: GET,PUT,POST,HEAD,DELETE

what should I do differently?

jb-alvarado

jb-alvarado posted a new bug report

axios-module •

bug progress: false, in post

Version

v5.9.3

Reproduction link

https://codesandbox.io/s/codesandbox-nuxt-hu20j

Steps to reproduce

When you ran a post command the progress will always be visible.

What is expected ?

{ progress: false } should hide the progress bar.

What is actually happening?

The progress bar is shown every time the request is made.

meatherly

meatherly posted a new bug report

axios-module •

bug settings headers in nuxt.config.js doesn't actually add the headers you set

Version

v5.9.0

Reproduction link

https://github.com/meatherly/nuxtjs-axios-bug

Steps to reproduce

Set the common headers in the nuxt.config.js for the axios module. Then make a request with the axios module.

What is expected ?

It should merge the headers you add to the config with the default like the documentation says.

What is actually happening?

The headers are not changing.

Additional comments?

I've created a example repo to recreate the bug.

  • Start up the project.
  • Load the index page.
  • Inspect the request to https://jsonplaceholder.typicode.com/posts/1 in the dev tools.

You should see that the common header set in nuxt.config.js is missing from the request when it shouldn't be.

moleCuleFFF

moleCuleFFF posted a new bug report

axios-module •

bug Typings are incorrect for default axios within context

Version

v5.9.0

Reproduction link

http://nofreakingway.com

Steps to reproduce

const cms: Plugin = (context, inject) => {
console.log((context.app.$axios as AxiosStatic).create());
};

$axios in this instance uses the interface NuxtAxiosInstance which does not include the create method.

What is expected ?

$axios should be an extended instance of AxiosStatic not AxiosInstance

What is actually happening?

$axios is an instance of AxiosInstance