• 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.

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

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 2 Posters 2.2k 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 Nov 29, 2017, 5:51 PM

    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 Nov 30, 2017, 9:05 AM Reply Quote 0
    • ? Offline
      A Former User @henrikra
      last edited by Nov 30, 2017, 9:05 AM

      @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 Dec 1, 2017, 8:20 AM Reply Quote 0
      • H Offline
        henrikra @Guest
        last edited by Dec 1, 2017, 8:20 AM

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

        ? 1 Reply Last reply Dec 1, 2017, 9:37 AM Reply Quote 0
        • ? Offline
          A Former User @henrikra
          last edited by Dec 1, 2017, 9:37 AM

          @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 Dec 4, 2017, 12:01 AM

            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
            • 1 / 1
            1 / 1
            • First post
              1/5
              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