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.

    missing 'Access-Control-Allow-Origin'

    Scheduled Pinned Locked Moved Troubleshooting
    10 Posts 6 Posters 5.7k Views 5 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.
    • BangeeB Offline
      Bangee Module Developer
      last edited by Bangee

      I’ll try to grab some informations from a JSON Data feed.
      But I’ve got always this error:

      Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf http://beny.ch/ironman/2015. (Grund: CORS-Kopfzeile 'Access-Control-Allow-Origin' fehlt).
      ironman: Could not load data.
      
      console.error(message);
      

      Datalink:
      http://beny.ch/ironman/2015

      here is the code to grab the content:

      		var ironmanRequest = new XMLHttpRequest();
      		ironmanRequest.open("GET", url, true);
      		ironmanRequest.onreadystatechange = function() {
      			if (this.readyState === 4) {
      				if (this.status === 200) {
      					self.processIronman(JSON.parse(this.response));
      				} else if (this.status === 401) {
      
      					self.updateDom(self.config.animationSpeed);
      
      					Log.error(self.name + ": Error forbidden");
      					retry = false;
      				} else {
      					Log.error(self.name + ": Could not load data.");
      				}
      
      				if (retry) {
      					self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
      				}
      			}
      		};                
      		ironmanRequest.send();
      

      How can I fix that?

      Thanks for helping me :-)

      1 Reply Last reply Reply Quote 0
      • KirAsh4K Offline
        KirAsh4 Moderator
        last edited by KirAsh4

        This comes up quite often, not just here on the MM² forums, but out in the wild too:

        http://lmgtfy.com/?q=Access-Control-Allow-Origin

        Basically the answer is: you can’t do that … cross-domain … security … find proper API … all of the above …

        A Life? Cool! Where can I download one of those from?

        RedNaxR 1 Reply Last reply Reply Quote 0
        • RedNaxR Offline
          RedNax Module Developer @KirAsh4
          last edited by RedNax

          @KirAsh4 Well, not strictly true ;) https://forum.magicmirror.builders/topic/157/mmm-opentherm
          But yes, you’ll need to fix the source!

          1 Reply Last reply Reply Quote 0
          • paviroP Offline
            paviro Admin
            last edited by

            Just use a node_helper.js to get around the access-allow-origin policy.

            We're all stories in the end. Just make it a good one, eh?

            – The Doctor

            1 Reply Last reply Reply Quote 0
            • BangeeB Offline
              Bangee Module Developer
              last edited by

              After googleing 1000 different websites I’ve used the nood_helper.js solution.

              And to load the nood_helper.js I had to restart electron. pm2 restart mm
              that coast me another hour to find out why it was no loading :-):gun: :hammer:

              1 Reply Last reply Reply Quote 0
              • K Offline
                KrawallKurt
                last edited by

                I am facing the same problem. Could you please give an example, how you used node_helper.js to circumvent the access-allow-origin policy?

                Thanks!

                1 Reply Last reply Reply Quote 0
                • yawnsY Offline
                  yawns Moderator
                  last edited by

                  Like here for example:
                  https://github.com/yawnsde/MMM-RNV

                  You use request instead.

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    KrawallKurt
                    last edited by KrawallKurt

                    Thank you!

                    And why does it have to be in node_helper, not in the main script? Sorry, if this question sounds stupid, I’m new to developing modules.

                    Also, is there a reason for declaring var self = this; and using self.func instead of this.func? I have seen this quite a bit and couldn’t understand why people do this…

                    yawnsY 1 Reply Last reply Reply Quote 0
                    • yawnsY Offline
                      yawns Moderator @KrawallKurt
                      last edited by

                      @KrawallKurt
                      Please note I am not an experienced javascript developer either. When using addon modules/libraries like request you use the node_helper.js to load this library. I am not sure if it is not possible at all to do so in the main module file or if it is just complicated. Maybe @strawberry-3-141 can clarify :)

                      self = this was used in other modules and I added it to my module as well, because I did not want to possibly break something by leaving it out. There is a lot of discussion on the web why this is used and if this still should be used.

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        KrawallKurt
                        last edited by

                        Concerning the self=this question, I found a neat article giving som explanations: https://alistapart.com/article/getoutbindingsituations

                        The other question: Could it be, that node_helper is executed on the server and the main script is executed on the client?

                        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