kontent-ai / delivery-sdk-js

Kontent Delivery SDK for Javascript
https://kontent.ai
MIT License
50 stars 34 forks source link

Possibility to set base url for api calls #34

Closed sesigl closed 6 years ago

sesigl commented 6 years ago

Hi,

is there a way to set the base url for accessing kentico cloud? I would like to proxy all calls to protect sensitive data. Is there are global config parameter available?

If not can you please add a configuration?

Instead of calling: https://preview-deliver.kenticocloud.com/{key}/items?system.type=article

it should call: https://{custom url}/items?system.type=article

when set.

edouardr commented 6 years ago

The urls for delivery and preview API are set in the QueryService class as private readonly attributs.

What about exposing them in the DeliveryClientConfig class? QueryService is already instantiated with the config object.

sesigl commented 6 years ago

Sounds Good for me. Looking forward to an implementation and documentation ;).

petrsvihlik commented 6 years ago

See how it's implemented in the .net sdk for reference.

sesigl commented 6 years ago

alright, so what do you mean by that? Do you ask me to contribute ? Or will you do/delegate it?

I'm open minded in this case :).

petrsvihlik commented 6 years ago

@Journerist sorry for confusion, it was rather a generic remark, not addressed to anyone in particular :)

It would be great if you could take care of it.

So what we did in the .NET SDK is that we introduced a DeliveryOptions object, adjusted DeliveryClient's constructors. And here's an example of how it can be used: https://github.com/Kentico/delivery-sdk-net/wiki/Using-the-ASP.NET-Core-Configuration-API-and-DI-to-Instantiate-the-DeliveryClient.

I'm not saying we should do it the exactly same thing but the general look&feel should be somewhat similar :)

Please let us know if you're willing to contribute so that we can assign the issue to you.

Enngage commented 6 years ago

Hey guys,

This is a good idea. I implemented it so that you can specify base urls when instantiating DeliveryClientConfig. I published it in 2.1.2 release:

new DeliveryClientConfig('projectId', [], {
      baseUrl: 'http://customurl.com',
      basePreviewUrl: 'http://custompreview.com'
    });

Let me know how that works and if you have any further suggestions.

sesigl commented 6 years ago

@Enngage thank you, this is awesome. I'll try it this evening and give you feedback if this works for me.

sesigl commented 6 years ago

I already love it, works amazingly. Finally I can get rid of my ugly hack :P. Thanks a lot ! <3