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

readFileSync

Scheduled Pinned Locked Moved Development
17 Posts 3 Posters 10.0k Views 1 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.
  • M Offline
    MichMich Admin
    last edited by May 19, 2016, 5:04 PM

    Just so you know, the node_helper can serve files as well: https://github.com/MichMich/MagicMirror/tree/master/modules#thisexpressapp

    1 Reply Last reply Reply Quote 0
    • K Offline
      KirAsh4 Moderator
      last edited by May 19, 2016, 5:11 PM

      I saw that when I was fiddling with some other stuff, but never actually tested it. Is that path relative to the actual module location? Or MM’s installation? Or the user that’s running MM? So if '/foo/bar/baz' is defined, where does it start?

      /foo/bar/baz? (OH PLEASE SAY NO, for the love of all that is sacred, tell me Node.js does NOT allow system reads like that!)
      $HOME/foo/bar/baz ?
      $HOME/MagicMirror/foo/bar/baz?
      $HOME/MagicMirror/modules/foo/bar/baz?
      $HOME/MagicMirror/modules/<MODULE>/foo/bar/baz?
      

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

      1 Reply Last reply Reply Quote 0
      • M Offline
        MichMich Admin
        last edited by May 19, 2016, 5:22 PM

        If you are referring to this snippet:

        start: function() {
            this.expressApp.get('/foobar', function (req, res) {
                res.send('GET request to /foobar');
            });
        }
        

        The /foobar is referring to the url: http://localhost:8080/foobar

        1 Reply Last reply Reply Quote 0
        • K Offline
          KirAsh4 Moderator
          last edited by May 19, 2016, 5:30 PM

          Ah, so it’s still an HTTP call then, not a simple fileread from disk.

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

          1 Reply Last reply Reply Quote 0
          • M Offline
            MichMich Admin
            last edited by May 19, 2016, 5:41 PM

            Exactly.

            1 Reply Last reply Reply Quote 0
            • K Offline
              KirAsh4 Moderator
              last edited by May 19, 2016, 5:44 PM

              So then the question is still, where is that '/foobar' ? What’s that in relation to? The MM install? The module’s folder?

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

              M 1 Reply Last reply May 19, 2016, 5:58 PM Reply Quote 0
              • M Offline
                MichMich Admin @KirAsh4
                last edited by MichMich May 19, 2016, 6:39 PM May 19, 2016, 5:58 PM

                @KirAsh4 it hasnt got anything to do with a file. It’s just a request, if you want to respond with the contents of a file, you need to do that yourself or use the following method if you want to feed a full folder:

                this.expressApp.use("/foobar" + this.name, this.expressApp.static(this.path + "/foobar"));
                
                1 Reply Last reply Reply Quote 0
                • K Offline
                  KirAsh4 Moderator
                  last edited by May 19, 2016, 6:18 PM

                  No, it doesn’t have anything to do with the contents. It has to do with where that file resides on the physical system. For example, a request to a default Apache installation will look for a file in '/var/www/html/' or '$USER/public_html' or whatever the system admin has configured it as. In this case, this is a specific request through the Node.js system, being called by MM, so where does it look for that file? Within the user’s folder? Within MM’s installation folder? Within the actual module’s folder? Or does Node.js allow access to the entire file system? So that if I do a call such as:

                  this.expressAp.use("/etc/passwd")
                  

                  will I actually get the contents of the system’s '/etc/passwd' file, or is going to try to read '/path/to/MM-install/etc/passwd' or some other path?

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

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    MichMich Admin
                    last edited by May 19, 2016, 6:37 PM

                    I’ve got the feeling we’re talking about something different.

                    The example:

                    this.expressApp.get('/foobar', function (req, res) {
                            res.send('GET request to /foobar');
                    })
                    

                    does not serve any file. So talking about file location doesn’t make any sense in this case. In this example It just serves the text string GET request to /foobar

                    In the second example:

                    this.expressApp.use("/foobar" + this.name, this.expressApp.static(this.path + "/foobar"));
                    

                    only the express.static(root, [options]) part refers to a file or folder. The root argument refers to the root directory from which the static assets are to be served.

                    More info about express.static can be found here: http://expressjs.com/en/api.html#express.static

                    K 1 Reply Last reply May 19, 2016, 6:43 PM Reply Quote 0
                    • K Offline
                      KirAsh4 Moderator @MichMich
                      last edited by May 19, 2016, 6:43 PM

                      @MichMich said in readFileSync:

                      The root argument refers to the root directory from which the static assets are to be served.

                      That’s part of the answer I was looking for. Specifically, 'from which the static assets are to be served'. Now to figure out where those are, or where they are allowed to be rather. Basically I’m looking at it from a security stand point. Where is this thing going to allow a user to get to, to fetch a file.

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

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 2 / 2
                      2 / 2
                      • First post
                        11/17
                        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