• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Module with HTTP Request

Scheduled Pinned Locked Moved Development
10 Posts 4 Posters 1.5k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    Jalibu Module Developer @1BlauNitrox
    last edited by Jan 17, 2022, 5:46 PM

    Hi @1blaunitrox,

    1. I’d recommend to use the fetch API and not XMLHttpRequest.
    2. 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.
    1 1 Reply Last reply Jan 17, 2022, 5:55 PM Reply Quote 0
    • 1 Offline
      1BlauNitrox @Jalibu
      last edited by Jan 17, 2022, 5:55 PM

      @jalibu is it possible to change the port in the api?
      In my main.ts file I have

      await app.listen(3000);
      

      Can I change it to 8080?

      J 1 Reply Last reply Jan 17, 2022, 6:04 PM Reply Quote 0
      • S Away
        sdetweil @1BlauNitrox
        last edited by sdetweil Jan 17, 2022, 5:57 PM Jan 17, 2022, 5:57 PM

        @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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 1
        • J Offline
          Jalibu Module Developer @1BlauNitrox
          last edited by Jalibu Jan 17, 2022, 6:05 PM Jan 17, 2022, 6:04 PM

          @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 :-)

          1 1 Reply Last reply Jan 17, 2022, 6:09 PM Reply Quote 0
          • 1 Offline
            1BlauNitrox @Jalibu
            last edited by Jan 17, 2022, 6:09 PM

            This post is deleted!
            1 1 Reply Last reply Jan 17, 2022, 6:11 PM Reply Quote 0
            • 1 Offline
              1BlauNitrox @1BlauNitrox
              last edited by Jan 17, 2022, 6:11 PM

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • S Offline
                sony8943
                last edited by Jul 13, 2023, 9:38 AM

                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?

                S 1 Reply Last reply Jul 13, 2023, 11:16 AM Reply Quote 0
                • S Away
                  sdetweil @sony8943
                  last edited by sdetweil Jul 13, 2023, 11:38 AM Jul 13, 2023, 11:16 AM

                  @sony8943 currently we do not have user/password capability.

                  maybe you could put a proxy server with authentication in front

                  https://devopscube.com/setup-and-configure-proxy-server/

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  S 1 Reply Last reply Jul 13, 2023, 12:24 PM Reply Quote 0
                  • S Offline
                    sony8943 @sdetweil
                    last edited by Jul 13, 2023, 12:24 PM

                    @sdetweil thanks

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Enjoying MagicMirror? Please consider a donation!
                    MagicMirror created by Michael Teeuw.
                    Forum managed by Sam, technical setup by Karsten.
                    This forum is using NodeBB as its core | Contributors
                    Contact | Privacy Policy