janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

How to run example app #74

Closed mikevbaker closed 6 years ago

mikevbaker commented 6 years ago

I'm not sure if the example app has a bug or if I'm not running it correctly. What are the instructions for getting the example up and running? I tried running 'node app.js' in the node js console window and I get

ko.applyBindings(new ViewModel()); ^ ReferenceError: ko is not defined at Object. (E:\Playground\OData\o.js-master\example\app.js:78:1) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

I tried just opening up the index.html app in my browser and when it runs the query to the service I get an error:

oException message : "Request to http://services.odata.org/V4/%28S%28wptr35qf3bz4kb5oatn432ul%29%29/TripPinServiceRW/People?$format=json&$top=3 failed with HTTP status 404." name : "o.js exception"

I used the Chrome debugging tool to trace the operation and it's happening at o.js:1413 and the ajaxRequest.status is 0. If I copy the uri and paste it into chrome as-is then I get the data I'm looking for without issues.

Perhaps I didn't set it up right. I downloaded the zip file and extracted it into a local playtime folder... E:\Playground\OData\o.js-master\example and I'm trying to run it from there. Am I running the example incorrectly? Is it supposed to be running through a server environment via localhost such as node? How should that be invoked?

TIA - mike

janhommes commented 6 years ago

Can you try it with a simple http server? Maybe this one.

It was running in Browser without any server, but I guess to recent changes to the odata.org endpoint they are checking the origin header and don't allow not-set headers. Or maybe the Chrome security is blocking it.

mikevbaker commented 6 years ago

I uploaded the example folder and the o.js & o.min.js files to my server on GoDaddy and I get the following in the console:

Failed to load http://services.odata.org/V4/%28S%28wptr35qf3bz4kb5oatn432ul%29%29/TripPinServiceRW/People?$format=json&$top=3: Response for preflight is invalid (redirect) o.min.js:1 Uncaught n {message: "Request to http://services.odata.org/V4/%28S%28wpt…?$format=json&$top=3 failed with HTTP status 404.", name: "o.js exception"}

Note that it says status is 404 but it actually returns with status==0 and the 404 is being substituted by o.js. I searched for status==0 and I found that some of the reasons this can happen is redirect (which is noted in the 'Failed to load' message). In other developments... I was able to get o.js working in my application. It was ridiculously easy. Just a tag in the html, then create and use the o object as described in OData-JavaScript-library-o.js-explained [Edit] also - it works locally without a server needed. Perhaps cause my own development testing service doesn't do CORS.

Mike

janhommes commented 6 years ago

Thanks, Mike!

I verified that and you are right, it is not working. We need to switch to https (it seems the odata team is now enforcing it) and therefore also change smth in our main code. Basically, we had a property called isCors which has nothing to do with CORS (don't know what came over me that made me name that CORS ;) ). So I renamed it. I put everything in this PR #73, which I like to use as the 0.3.9 release. If you like to check?

Regards Jan

mikevbaker commented 6 years ago

OK. Checked it out. Works both locally by just double-tapping the html file in the browser, and also when I uploaded it to my test folder on GoDaddy. BTW - I first tried to switch to the 0.4.0 branch but that contains v0.2.2

janhommes commented 6 years ago

Yeah, thanks for the hint. That is an old branch which was not closed.

I published 0.4.0. I will close that issue. The demo can be seen here: https://janhommes.github.io/o.js/example/

Regards Jan