Comments (11)
Hi @Enngage ,
Funny, I actually wanted to contact you next week about some issues I have with implementing the kentico-js-sdk in a Nuxt environment. So i am glad you reached out to me.
I started this repo because i work a lot with Kentico(Cloud) and i am a great fan of Nuxtjs ánd to prevent to repetitive task of setting up the KenticoCloudDeliveryTypeScriptSDK.
Yesterday I found the issue which I was running into ( #3 ), the error is somewhat misleading but it is the rxjs which is causing that problem as Nuxt supports only promises (in it's default workflow). So client side calls can now be done!
I'm still having problems however getting the server-call to work. I keep getting the error:
"XMLHttpRequest is not supported by your browser"
Next week i will digg into it a bit more. But i am sure it has something to do with rxjs as well.
Nice to hear that you are refactoring the SDK. As for me, it would be great if rxjs would be optional (or an extension). I think for most of the projects promisses are sufficient enough.
Kind Regards,
Alfred
from kentico-kontent-nuxt-module.
Lucky coincidence :) I think I might able to point you to right direction with points you mentioned:
- The whole SDK is built on top of
rxjs
which I believe is superior to Promises so I don't think this is gonna change, but from a consumer point of view, it should't make a difference becauseObservable
can be easily converted to aPromise
(see rxjs docs) so you would be able to do something like:
let promise = deliveryClient.items().get().toPromise()
I'm in a middle of refactoring to rxjs 6
so the syntax will change a bit, but the general idea will be the same.
- The problem you have with
XMLHttpRequest
is because this class is implemented by browsers (Firefox, Google, Opera ...), but does not have any implementation in Node.js. There are other HTTP clients for node.js, but they work quite differently so any code that needs to make HTTP requests need to use different libraries based on the environment. Previously, I had support for both node.js and browser in the same SDK, but that turned out to be a bad idea beacuse bundling such libraries (i.e. via webpack for production) will fail because you can't for example bundle node.js code for use in browser - browser doesn't know about the classes and will throw exceptions (and vice versa)
Thats why I separated the code into KenticoCloudDeliveryNodeSDK. This library depends on the main one and only implements HTTP service, but its not up to date yet (I will bump this up with the release of the new version).
Though, I'm not sure why you downgraded the library as the above was not changed in v3, only the build process was.
from kentico-kontent-nuxt-module.
-
Yes, the toPromise method works fine! So yesterday i updated the readme.md and i also upgraded the kentico-cloud-delivery-typescript-sdk package to version 3.1.0 again.
-
I also did a quick test to see if i could do a server-side-call with the kentico-cloud-delivery-node-sdk in my nuxt test application and that works too! So in theory i could add another global plugin ($deliveryNodeClient for instance) but then the user has to be aware of using $deliveryNodeClient server-side and $deliveryClient client-side. I guess this can be confusing at first and is error-prone. Take Axios for instance. It is always $axios to do a http-call, no matter if you are client or server side.
I have to think about this some more. Maybe i can come up with another solution, i know there are ways to detect if the call is done server or client side within nuxt so maybe that could help me out (by using a factory for instance).
from kentico-kontent-nuxt-module.
Awesome :) I totally forgot you can get promise just by calling getPromise
method that I've prepared in the past:
let promise = deliveryClient.items().getPromise()
In v4 I've changed this so you either call getObservable
or getPromise
.
I actually didn't know about Axios. I've been researching http clients and finally decided to go with xhr
in v4 (as a substite for rxdom
). I think I'll have to rethink this because the Axios looks really good and my tests seems to be working with it perfectly fine.
One thing that I'll have to test is how it bundles up with WebPack and if there are any dynamic includes or anything that would break AOT builds.
It would be awesome to have the library working both in node and browser and this could solve one part of the issue, the other is HTML parser. There currently isn't any node.js/browser parser apart from Parse5 which I wan't to get rid of..
Anyway - maybe wait with the server side NUXT client a bit.
from kentico-kontent-nuxt-module.
Turns out the Axios is pretty good and I'll be using that for the library. Seems like I will deprecate the node client afterall.
If you want to test it, try installing beta version 4.0.0-beta.5
which should now work in both browser & node. Note that there are some API changes, which should be fixed in docs - https://github.com/Enngage/KenticoCloudDeliveryTypeScriptSDK/tree/major-version-node-js-support
from kentico-kontent-nuxt-module.
@Enngage : Cool, thanks for the update! Axios FTW!
I have little time this week but hopefully I find some time to check it out. I'll keep you posted!
from kentico-kontent-nuxt-module.
I just did a quick test to see if it works but i am getting an error:
I am running this piece of code:
this.$deliveryClient
.items()
.type('page')
.getPromise()
.then(response => console.log('DeliveryClient Response', response));
But that is giving me this error:
Do you have any clue what is going wrong?
from kentico-kontent-nuxt-module.
from kentico-kontent-nuxt-module.
Great, it works now!! I actually got a warning for installing rxjs but ignored it because i was in a hurry.
I will release a new version this afternoon so we can do some more testing internally! But this sure looks promising!
Any roadmap for releasing this (major-version-node-js-support) branch/version as a production version?
from kentico-kontent-nuxt-module.
from kentico-kontent-nuxt-module.
Closed this issue because the new Kentico Cloud Delivery SDK is implemented!
from kentico-kontent-nuxt-module.
Related Issues (18)
- Add a tracking header HOT 2
- Rebranding to Kentico Kontent HOT 5
- Announce: Prepare for Fair user policy updates HOT 1
- Update @kentico/kontent-delivery to latest. HOT 1
- Support TypeResolvers HOT 1
- Cannot read property 'items' of undefined HOT 1
- DeliveryClient requests fail when secure mode is enabled HOT 2
- Make typescript types available HOT 7
- (re)Add tests for the cache-service
- Support Server Side calls HOT 6
- Upgrade to Kentico Delivery JS SDK 11 HOT 2
- Migrate kontent-nuxt3-module into this repository
- The automated release is failing 🚨 HOT 1
- Update to @kontent-ai/*
- Remove momentJS dependency HOT 1
- Docs for Rich Text resolver are no longer valid HOT 1
- The automated release is failing 🚨 HOT 11
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 kentico-kontent-nuxt-module.