New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing extending axios #98

Closed
mathieutu opened this Issue Mar 13, 2018 · 5 comments

Comments

Projects
3 participants
@mathieutu

mathieutu commented Mar 13, 2018

Hi.
I've spent several hours to understand why my axios default config (added in ~/plugins/axios.js as explained here) were not applied when fetchUser was called, at the app init.

In fact, you add the auth plugin just after the first axios plugin, so it inits before the config file:

const index = this.options.plugins.findIndex(p =>
/axios\.js$/.test(p.src || p)
)
this.options.plugins.splice(index + 1, 0, join(this.options.buildDir, dst))

With that, I can't use this module at all, because all the axios config I need (especially x-api-key header) is set after the auth plugin.
😞

Do you have any quick solution, or do you want a PR?

This question is available on Nuxt.js community (#c71)

@breakingrobot breakingrobot added this to To Do in 4.0 via automation Mar 27, 2018

@breakingrobot

This comment has been minimized.

Member

breakingrobot commented Mar 27, 2018

@mathieutu We would appreciate a PR on this one, still if you don't have the time, we will try to fix it asap ;)

@mathieutu

This comment has been minimized.

mathieutu commented Mar 27, 2018

ok, I'll do it when I get some time.

@mathieutu

This comment has been minimized.

mathieutu commented Mar 27, 2018

@breakingrobot do you see any problem if instead of adding the plugin just after $axios we just push it at the end of plugins array and let the user choose the order? Why did you do this particular trick?

-  // ...add plugin just after $axios
-  const index = this.options.plugins.findIndex(p =>
-    /axios\.js$/.test(p.src || p)
-  )
-  this.options.plugins.splice(index + 1, 0, join(this.options.buildDir, dst))

+  // just push the plugin at the end
+  this.options.plugins.push(join(this.options.buildDir, dst))

Thanks for your answer.

@pi0

This comment has been minimized.

Member

pi0 commented Apr 1, 2018

@mathieutu But we can't add it to the end. Users may provide plugins to extend auth too (just like axios) (thus depend on it). BTW Why don't use top-level axios configuration? If it is just to prevent users confusing we may remove auto axios import.

Update: now auth uses plugins.push and instead has a plugins option to allow extending.

pi0 added a commit that referenced this issue Apr 1, 2018

@mathieutu

This comment has been minimized.

mathieutu commented Apr 1, 2018

Sounds perfect for me!
👌

@mathieutu mathieutu closed this Apr 1, 2018

4.0 automation moved this from To Do to Done Apr 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment