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

missing 'Access-Control-Allow-Origin'

Scheduled Pinned Locked Moved Troubleshooting
10 Posts 6 Posters 5.6k 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.
  • B Offline
    Bangee Module Developer
    last edited by Bangee Jul 19, 2016, 8:11 AM Jul 19, 2016, 8:04 AM

    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
    • K Offline
      KirAsh4 Moderator
      last edited by KirAsh4 Jul 19, 2016, 4:56 PM Jul 19, 2016, 4:55 PM

      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?

      R 1 Reply Last reply Jul 19, 2016, 8:17 PM Reply Quote 0
      • R Offline
        RedNax Module Developer @KirAsh4
        last edited by RedNax Jul 19, 2016, 8:17 PM Jul 19, 2016, 8:17 PM

        @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
        • P Offline
          paviro Admin
          last edited by Jul 19, 2016, 8:59 PM

          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
          • B Offline
            Bangee Module Developer
            last edited by Jul 20, 2016, 7:00 AM

            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 May 11, 2017, 4:54 PM

              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
              • Y Offline
                yawns Moderator
                last edited by May 11, 2017, 8:20 PM

                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 May 11, 2017, 9:00 PM May 11, 2017, 8:46 PM

                  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…

                  Y 1 Reply Last reply May 12, 2017, 8:47 AM Reply Quote 0
                  • Y Offline
                    yawns Moderator @KrawallKurt
                    last edited by May 12, 2017, 8:47 AM

                    @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 May 12, 2017, 11:14 AM

                      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