Comments (7)
@pdath Thank you for bringing this to my attention! I just saw your post on the Meraki forums. I agree that any fix that's done will have to be carefully laid out, as this is essentially a breaking bug that seems to be designed as such.
There's two things that can be done:
- Add a method that allows you to change the base url
- Enforces that the correct request operation is being made. This would be in the form of either making a fork of axios and relevant libraries to fix this behaviour or manually applying a "monkey patch" for the relevant libraries until. A PR could be made to address this bug for the respective libraries.
from node-meraki-dashboard.
I'll take some time next week to write a few unit tests to document this bug and figure out how exactly this bug can be fixed for now.
from node-meraki-dashboard.
I had a go at adding a method to change the base url. The problem is you dont know what baseurl to use until after you have made at least one API call. axios.create() gets called before any function executes, so you can't seem to change it afterwards (or at least I could not).
I also had a play with changing both dataProcessor and get() and trying to update the baseURL with response.request.socket.servername. So basically the last request is used to update the baseURL for the next request. As long as at least one get() request is made first, subsequent post() requests would work. I thought this would be most elegant, as an application doesn't have to be aware of anything happening under the hood - everything would just work.
But I couldn't find a way to update the axios.create() above ...
I had a play with changing the function MerakiDashboard(apiKey) to function MerakiDashboard(apiKey,baseURL). Then it doesn't break anything that is using it. It didn't seem very elegant though.
Basically the application using it would make a call to dashboard.organizations.list(), then search for the organisation you want, extract out the url, and then create/replace the existing "dashboard" object but this time include the new URL. Not so pretty.
from node-meraki-dashboard.
More specifically, the issue is that axios uses follow-redirects.
It seems that the module follow-redirects deliberatly limits the use of http methods to "read" types. It doesn't consider POST to be "safe" as it is a "write" method so is changing it on purpose to a GET.
var SAFE_METHODS = { GET: true, HEAD: true, OPTIONS: true, TRACE: true };
https://github.com/follow-redirects/follow-redirects/blob/master/index.js#L11
from node-meraki-dashboard.
This change could be a breaking change by the looks of it, and the nature of the fix needed would make the library unstable for the time being. There might be a way to find that url from the Meraki Dashboard itself, since that url has some information on the org and other things.
For changing the base url, it might just be a matter of calling axios.create
again, which seems reasonably easy.
from node-meraki-dashboard.
Just trying to learn more about this.
I see a lot of examples simply do a:
const axios = require('axios');
And they configure defaults with something like:
axios.defaults.baseURL = 'https://api.example.com';
Is there a reason why you create a seperate instance with axios.create()? I suspect if the seperate instance was removed then axios.defaults.baseURL could just be updated directly (untested).
from node-meraki-dashboard.
I didn't have a particular reason at the time, except maybe to enforce a sense of immutability and not deal with default or global variables and the bugs that can be created with them. It also would make implementing the base url change fix as a matter of replacing the axios instance with a new one.
from node-meraki-dashboard.
Related Issues (9)
- dashboard.devices.update - does not update HOT 11
- Implement recently added new API endpoints
- organization id containing 18 digits changing last 2 to 00 HOT 9
- Add testing/coverage
- What does "slightly opinionated" mean? HOT 2
- index.js missing HOT 2
- 2 New Group Policy API endpoints HOT 3
- API coverage error? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-meraki-dashboard.