Read the statement by Michael Teeuw here.
Module with HTTP Request
-
Hi @1blaunitrox,
- I’d recommend to use the fetch API and not XMLHttpRequest.
- The reason for failing is most probably the same-origin-policy as your API server runs on port 3000, which differs from the MagicMirror port, which is 8080 by default. One way to solve that is setting a
Access-Control-Allow-Origin
(CORS) header in your API response or to add some kind of a ajax-proxy in a node_helper.js file in your module.
-
@jalibu is it possible to change the port in the api?
In my main.ts file I haveawait app.listen(3000);
Can I change it to 8080?
-
@1blaunitrox the get request is not synchronous
meaning it returns back before it’s done
so you can’t call it in getDom()
as it will return before finished, and then getDom() will have the wrong status.
you typically start this in some timer routine, and when it returns, save the results, then call updateDom(), which will cause getDom() to be called
-
@1blaunitrox said in Module with HTTP Request:
Can I change it to 8080?
No, because it is blocked by MagicMirror ;-)
But what sdetweil says is of course true and on closer inspection this is the main problem in your code. Welcome to the world of asynchronous JavaScript :-) -
This post is deleted! -
This post is deleted! -
Hello i want to put user and password everytime i open local host or ip address; whatever to access magic mirror from browser .
How to put his setting in config.js? -
@sony8943 currently we do not have user/password capability.
maybe you could put a proxy server with authentication in front
-
@sdetweil thanks