eclipse-agail / agile-sdk

JavaScript Agile IoT SDK
Eclipse Public License 2.0
2 stars 4 forks source link

Modify the constructor to allow proxy routes. #33

Closed Exulansis closed 7 years ago

Exulansis commented 7 years ago

The issue

Currently due to these two lines in the constructor, the agile sdk can not be initialized with a relative url to agile-core. This means that no matter what url the user provides as the api parameter, it will always be modified to be an absolute path. This is not the case with the other parameters, namely idm and data.

What does this mean?

This creates problems when an application using agile sdk wants to proxy the api calls (for instance to avoid CORS issues or to make use of Docker's DNS).

For instance the Agile UI application tries to proxy all requests sent to the API endpoints (can be seen here ). In order for the requests to be proxied, Agile UI needs to send the requests through resin:2000/api/*. For this to happen the agile sdk would need to be initialized as follows:

var agile = agileSDK({
  api: '/api/agile-core',
  idm: '/api/agile-security',
  data: '/api/agile-data'
});

But currently this won't work. The idm and data endpoints will be configured correctly, but the api param will be modified and end up as the origin of the application initializing the sdk plus the suffix /api, in our case http://resin:2000/api, instead of http://resin:2000/api/agile-core. This makes it impossible to have the api calls to agile core proxied through a custom path, since it will always end up being origin+/api.

How did it work before?

The previous version of Agile UI (v0.3.7), initialized the SDK as follows: const agile = agileSDK('/api'); With the latest version of the sdk, this would result, as mentioned before in origin+/api, so as a coincidence it works, if it were initialized as const agile = agileSDK('/proxy');, it would not work as expected and still initialize to origin+/api