Skip to content
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
Closed

Allowing extending axios #98

mathieutu opened this issue Mar 13, 2018 · 5 comments

Comments

@mathieutu
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

mathieutu commented Mar 27, 2018

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

@mathieutu
Copy link
Contributor Author

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
Copy link
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 pushed a commit that referenced this issue Apr 1, 2018
@mathieutu
Copy link
Contributor Author

mathieutu commented Apr 1, 2018

Sounds perfect for me!
👌

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
Projects
No open projects
4.0
  
Done
Development

No branches or pull requests

4 participants