skydiver / ewelink-api

eWeLink API for JavaScript
https://www.npmjs.com/package/ewelink-api
MIT License
264 stars 108 forks source link

"can run on browsers, node scripts or serverless environment", but HOW? #157

Open jumpjack opened 3 years ago

jumpjack commented 3 years ago

Documentation says that this library "can run on browsers, node scripts or serverless environment", but how do we use it inside a browser, without node.js?

augustofagioli commented 2 years ago

Same shoes, now.

Serverless means different things depending on the context. It could mean using third party managed services like Firebase, or it could mean an event-driven architecture style. It could mean next generation compute service offered by cloud providers, or it could mean a framework to build Serverless application

https://www.serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb

dexter323i commented 1 year ago

+1 for this question!

I want to run a simple code with JS in Browser: Get all devices in a JSON, and work with the data. Repeat it in every minute. So far I did:

(async () => {

const connection = new ewelink({ email: '', password: '', region: 'eu', });

const devices = await connection.getDevices(); console.log(devices); })();


In console, I've got an error:
_Access to fetch at 'https://eu-api.coolkit.cc:8080/api/user/login' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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._

As far as I understand, it will never work this way, beacuse I would need to add some header parameters to the call. Could anyone help how to run it from brwoser?