sebmos / node-eufy-api

A simple JavaScript API to control EufyHome (Anker) smart light bulbs, switches and plugs.
Apache License 2.0
23 stars 7 forks source link

CORS issue at calling loadDevices #10

Open ihardyslide opened 4 years ago

ihardyslide commented 4 years ago

Hi,

I'm currently trying to implement a web dashboard on top of your node-eufy-api. Unfortunately, I can't access the Eufy API from the browser as it seems, failing with a CORS error:

Access to fetch at 'https://home-api.eufylife.com/v1/user/email/login' from origin 'http://localhost:8559' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Is there some way I can tell your library, that it should fetch the Eufy API with 'no-cors' option?

Thanks & br, Marco

sebmos commented 4 years ago

That's not possible, because Eufy's servers don't let you create an connection from an arbitrary domain. To create a web dashboard, you have to create a Node JS server application, which your browser connects to. That application will then connect to Eufy servers & devices.

Keep in mind that in order to interact with Eufy devices, that server needs to be running on a server on the same Wifi network as your Eufy devices.

ihardyslide commented 4 years ago

I see! Thanks!

ihardyslide commented 4 years ago

Sorry if I highjack this issue for a follow up, but now everything is set up as proposed. I am now getting Socket Closed error as soon as I try to .connect() to the lightbulb. Any ideas? image

Edit: They are in the same network btw!

sebmos commented 4 years ago

This looks like it's related to this issue https://github.com/sebmos/node-eufy-api/issues/2.

This is something that affects some, but not all devices. This appears to be a bug in Eufy devices that they need to fix. The workaround would be to connect directly to Eufy's servers, which hasn't been achieved yet independently of Eufy. (At least as far as I can see.)