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

Compliments: RemoteFile Configuration

Scheduled Pinned Locked Moved Troubleshooting
complimentsremotefileconfiguration
8 Posts 5 Posters 1.5k 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.
  • J Offline
    jacktar
    last edited by Apr 8, 2021, 10:48 AM

    Hi…
    I don’t consider myself to be a novice but setting up a remote compliments file is proving to be a real challenge.
    Unfortunately, IMO the documentation isn’t that great when targetting a remote file - I’ve tried all sorts of config lines but to no avail.

    e.g.

    remoteFile: 'http://localhost:8080/compliments.json'
    remoteFile: 'http://localhost:8080/modules/compliments.json'
    

    for localhost, also read 127.0.0.1 and its assigned IPv4 address - I even moved the file into different directories in the vain hope it was a webserver permissions problem.

    This is the (current) error in the debug window using localhost…

    Access to XMLHttpRequest at 'http://localhost:8080/compliments.json' from origin 'http://0.0.0.0:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
    compliments.js:134
    GET http://localhost:8080/compliments.json net::ERR_FAILED
    

    Similarly, I also tried…

    remoteFile: 'file://home/pi/MagicMirror/compliments.json'
    

    ALL ATTEMPTS to target a filesystem file (compliments.json) fail :( …

    compliments.js:134 GET http://0.0.0.0:8080/modules/default/compliments/file://home/pi/MagicMirror/compliments.json 404 (Not Found)
    

    I can only assume my notation is wrong somewhere/somehow!
    Incidentally, the file formatting appears to be correct so I’m convinced it’s the way I’m trying to ‘point’ the system at the json file.

    If anyone can help, I’d appreciate it. Not much hair left to pull out :(

    L 2 Replies Last reply Apr 8, 2021, 10:52 AM Reply Quote 0
    • L Offline
      lavolp3 Module Developer @jacktar
      last edited by Apr 8, 2021, 10:52 AM

      @jacktar said in Compliments: RemoteFile Configuration:

      compliments.js:134 GET http://0.0.0.0:8080/modules/default/compliments/file://home/pi/MagicMirror/compliments.json 404 (Not Found)

      You see the problem in the error message.
      The variable remoteFilegets appended to an existing path which is http://0.0.0.0:8080/modules/default/compliments/.

      You only need to put in the name of the file without a path and put your file into the compliments folder.

      How to troubleshoot modules
      MMM-soccer v2, MMM-AVStock

      1 Reply Last reply Reply Quote 0
      • L Offline
        lavolp3 Module Developer @jacktar
        last edited by lavolp3 Apr 8, 2021, 11:02 AM Apr 8, 2021, 10:59 AM

        @jacktar Here is the underlying function

        	/* complimentFile(callback)
        	 * Retrieve a file from the local filesystem
        	 */
        	complimentFile: function (callback) {
        		var xobj = new XMLHttpRequest(),
        			isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0,
        			path = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile);
        		xobj.overrideMimeType("application/json");
        		xobj.open("GET", path, true);
        		xobj.onreadystatechange = function () {
        			if (xobj.readyState === 4 && xobj.status === 200) {
        				callback(xobj.responseText);
        			}
        		};
        		xobj.send(null);
        	},
        

        Whenever you use a “http://” or “https://” path it takes the path as you have provided. If not it converts it to an absolute path using the this.file(this.config.remoteFile) method. This method uses the modules directory (like you can see in my post above) and appends the path you have given

        How to troubleshoot modules
        MMM-soccer v2, MMM-AVStock

        S J 2 Replies Last reply Apr 8, 2021, 11:13 AM Reply Quote 0
        • S Offline
          sdetweil @lavolp3
          last edited by Apr 8, 2021, 11:13 AM

          @lavolp3 another thing to say is

          the MagicMirror provided web server assumes

          modules is the root
          express is listening/watching for modules as the base path

          http://localhost:8080/modules/…

          the file can be anywhere further down

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • J Offline
            jacktar @lavolp3
            last edited by Apr 9, 2021, 5:11 PM

            Ok, thanks. Got that sorted now :)
            Hopefully this will help others with the same dilemma.
            I had read a post referencing the use of file://
            notation which, apparently, is a red-herring.

            Just for clarity to others, a local compliments.json
            file should be located in /pi/MagicMirror/modules/default/compliments/ directory and referenced using only the file name in the config file.

            e.g. remoteFile: 'compliments.json'

            K 1 Reply Last reply Apr 28, 2022, 6:34 AM Reply Quote 0
            • K Offline
              kayakbabe @jacktar
              last edited by Apr 28, 2022, 6:34 AM

              @jacktar said in Compliments: RemoteFile Configuration:

              Just for clarity to others, a local compliments.json
              file should be located in /pi/MagicMirror/modules/default/compliments/ directory and referenced using only the file name in the config file.
              e.g. remoteFile: ‘compliments.json’

              So… what happens if we update the compliments module? Do our customizations in the compliments.json file get wiped out?
              can we put the compliments.json somewhere else to protect it?

              S 1 Reply Last reply Apr 28, 2022, 11:43 AM Reply Quote 0
              • S Offline
                sdetweil @kayakbabe
                last edited by Apr 28, 2022, 11:43 AM

                @kayakbabe yes they will be lost.
                .NEVER edit the source files we provide.

                the design is that all your setting go in config.js
                and custom.css for colors etc.

                module :"compliments",
                position:"....",
                config:{
                    compliments:{
                               morning:[],
                                afternoon:[],
                              etc
                     }
                }
                

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Assassins
                  last edited by Apr 28, 2022, 4:05 PM

                  You can look here

                  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