ewelink-api
ewelink-api copied to clipboard
"can run on browsers, node scripts or serverless environment", but HOW?
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?
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
+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:
- install nodejs
- install ewelink-api with npm
- install browserify with npm
- convert ewelink-api code into a local js file with this command: browserify -r ewelink-api > el.js
- made html including this js file, and tried to run the example code:
<html>
<head>
<script src='el.js'></script>
<script>
const ewelink = require('ewelink-api');
(async () => {
const connection = new ewelink({
email: '<the email>',
password: '<password>',
region: 'eu',
});
const devices = await connection.getDevices();
console.log(devices);
})();
</script>
</head>
<body></body>
</html>
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?