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.

    What is right way to do http request on my custom module?

    Scheduled Pinned Locked Moved Troubleshooting
    5 Posts 2 Posters 2.5k Views 2 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.
    • H Offline
      henrikra
      last edited by

      At the moment I am calling my external endpoint with XMLHttpRequest in my custom module. But the server has CORS setting on. My current workaround for that is that I am adding webSecurity: false inside electronOptionsDefaults in js/electron.js file. This allows me to do requests to the server without CORS problem.

      My question is there a correct way to do http requests in custom modules? Are there any disadvantages in my current solution?

      ? 1 Reply Last reply Reply Quote 0
      • ? Offline
        A Former User @henrikra
        last edited by

        @henrikra
        If you have a plan to release that module publicly, you should provide instruction how people to do that solution.

        Usually, do your job in node_helper.js and send data to module with sendSocketNotification(). Your module can get the data with socketNotificationReceived(). It is a more kindly way to other people.

        H 1 Reply Last reply Reply Quote 0
        • H Offline
          henrikra @Guest
          last edited by

          @Sean Nice! Can you show example project where you have done it like this?

          ? 1 Reply Last reply Reply Quote 0
          • ? Offline
            A Former User @henrikra
            last edited by

            @henrikra
            Default news feed module doesn’t use xmlHttpRequest, but you can get an idea how to comunicate between module and node_helper.

            1 Reply Last reply Reply Quote 0
            • H Offline
              henrikra
              last edited by

              Thank you so much! You have guided me to right direction and now I am doing requests the right way in node_helper :)

              1 Reply Last reply Reply Quote 1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 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