Giter Club home page Giter Club logo

Comments (11)

peter-murray avatar peter-murray commented on May 27, 2024

The XMLHttpRequest is a CORS error. You are trying to access a website from another website or domain, look here for more details, https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS.

As for the dgram.createSocket, this is a Node.js module function. It does IO and is not one of the directly supported libraries in browserify. It may be possible to swap that out with a compatible library for a browser, like dgram-browserify, but I would have to look deeper into that. Considering it is not the API preferred approach, I don't think it's worth it.

I would suggest you look deeper into the CORS documentation link to see if you can narrow down you particular use case and whether or not there is something you can do about it.

If you get nowhere with that and can provide me with some source code example as to recreating the issue, then I would be able to look further into it.

from node-hue-api.

cascornelissen avatar cascornelissen commented on May 27, 2024

I'm sorry for the late reply. My motherboard failed the day after I opened this issue so I couldn't investigate further.

I tried to request the details via jQuery AJAX and got the correct response:

$.ajax({
    url: 'https://www.meethue.com/api/nupnp'
}).always(function(r) {
    console.log(r);
});

returns

[
    {
        id: "001788fffe158d63",
        internalipaddress: "192.168.2.2"
    }
]

I'll start investigating it further now but if you have any ideas I'd love to hear them 😃

from node-hue-api.

cascornelissen avatar cascornelissen commented on May 27, 2024

After checking the differences in network requests using Chrome devtools I noticed these differences:

My jQuery AJAX request has the request header accept: */* while the request made by node-hue-api has accept: application/json (as set in commands/traits/tApiMethod.js). When removing the || "application/json" from line 45 in that file I get the exact same request header as my jQuery AJAX request, so this isn't it.

The only other difference in requests is that the node-hue-api also has the cache-control: max-age=0 request header set.

Although I'm quite sure this is not what's causing it I'm still sharing it with you as it might give you something to think about.


I then changed my AJAX request to

$.ajax({
    url: 'https://www.meethue.com/api/nupnp',
    headers: {
        'accept': 'application/json',
        'cache-control': 'max-age=0'
    }
}).always(function(r) {
    console.log(r);
});

which returns the following error:

XMLHttpRequest cannot load https://www.meethue.com/api/nupnp. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

And I'm pretty sure that error is being caused by the cache-control header because the request returns the correct object when I remove that request header.

No idea if this is what's causing it again, but it might help!

from node-hue-api.

peter-murray avatar peter-murray commented on May 27, 2024

This is still a CORs issue. It has nothing to do with the headers that you have indicated. You are trying to access a website from another domain, and the meet hue.com/api/nupnp is not supporting your source address from your website.

from node-hue-api.

cascornelissen avatar cascornelissen commented on May 27, 2024

Although I'm fine with you closing this issue, it is not a simple CORS issue. The jQuery AJAX method is right above the upnpSearch method and is working correctly. I have no idea what's causing it but for now I'll simply use that AJAX call via jQuery to get the details and I'll probably switch to a different npm module in the near future.

Thanks for the help though.

from node-hue-api.

peter-murray avatar peter-murray commented on May 27, 2024

The error message you have provided is a CORS error. I have done a very simple conversion of the node-hue-api into a standalone self contained js file using browserify (which I assume you are still using).

I get a complete different result from you, in that request is screwing up the URL, into http://www.meethue.com:443/api/nupnp which is not valid, as it should be https, and if I fix the browserify generated code, then the CORS request executes correctly as restify sets the necessary cors related headers.

If you want me to look further into this, then you will have to provide me with the browserify command that you are running to generate the wrapper js file.

from node-hue-api.

peter-murray avatar peter-murray commented on May 27, 2024

I got the other bottom of the changing of the https to http, and it is related to how request and resultant browserify code works. It switches the request from https to http as my express server that I had running was running over http.

When I switched the express server over to run under https, the code works as expected and the call to meet hue.com/api/nupnp returns the value of the bridges on my network.

This library is not really written to support its use in the browser, but if you do run your express server under https, then it the search/discovery should function as you desire.

from node-hue-api.

cascornelissen avatar cascornelissen commented on May 27, 2024

First of all, thanks for the further investigations and detailed information on your discoveries.

I'm running a simple BrowserSync server to develop the application but it will later on be packaged using nw.js, so no express there as far as I know.

I did some quick debugging and the hue.nuphpSearch() function results in a request header Request URL:https://www.meethue.com/api/nupnp so I don't think that the protocol is what is going wrong, unfortunately.

For your first question, I'm using the gulp-browserify module in combination with gulp-watchify based on this snippet.

If you want, I can send you the entire project so you can debug a little yourself.

I'll try and see if I can debug some more later today or tomorrow regarding the protocol issues.

from node-hue-api.

peter-murray avatar peter-murray commented on May 27, 2024

I am happy to take a look at your project, if you can make the source available to me.

Sent from my iPad

On 26 Jul 2015, at 12:30, Cas Cornelissen <[email protected]mailto:[email protected]> wrote:

First of all, thanks for the further investigations and detailed information on your discoveries.

I'm running a simple BrowserSync server to develop the application but it will later on be packaged using nw.js, so no express there as far as I know.

I did some quick debugging and the hue.nuphpSearch() function results in a request header Request URL:https://www.meethue.com/api/nupnp so I don't think that the protocol is what is going wrong, unfortunately.

For your first question, I'm using the gulp-browserify module in combination with gulp-watchify based on this snippethttps://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md.

If you want, I can send you the entire project so you can debug a little yourself.

Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-124974342.

from node-hue-api.

cascornelissen avatar cascornelissen commented on May 27, 2024

@peter-murray, is there any way to contact you privately as I would like to keep my project private for some time.

from node-hue-api.

peter-murray avatar peter-murray commented on May 27, 2024

I have added you as a collaborator on a private repository under my account called "private-repo", we can utilize that.

from node-hue-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.