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

How can i pass query / parameters from URL to module

Scheduled Pinned Locked Moved Solved Development
12 Posts 3 Posters 2.6k Views 3 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.
  • S Away
    sdetweil @AxLed
    last edited by Mar 29, 2020, 4:49 PM

    @AxLed cooll… standing by!

    Sam

    How to add modules

    learning how to use browser developers window for css changes

    S 1 Reply Last reply Mar 30, 2020, 12:26 PM Reply Quote 0
    • S Away
      sdetweil @sdetweil
      last edited by sdetweil Mar 30, 2020, 12:29 PM Mar 30, 2020, 12:26 PM

      @AxLed so, it should be as simple as

      const express = require('express')
      
      // setup server path handler, for http get request
      this.expressApp.get("/MMM-Navigate",(req,res) =>{this.someFunction(req,res)});
      
      // handler dump request object
      someFunction: function(request,response){
           console.log("request data="+JSON.stringify(request))
          response.send("Hello from MMM-Navigate");
      }
      

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • ? Offline
        A Former User
        last edited by A Former User Mar 30, 2020, 1:32 PM Mar 30, 2020, 1:31 PM

        Here is another example of express;

        const express = require('express')
        const bodyParser = require('body-parser')
        
        // in your member function of node_helper.js, usually it will be `.start()`
        
        this.expressApp.use(bodyParser.json())
        this.expressApp.use(bodyParser.urlencoded({extended: true}))
        var process = (req, res) => {
          var subpath = req.params.subpath
          if (CHECK_SOME_CONDITION) {
            var requestObj = {
              path: subpath,
              query: req.query,
              post: req.body,
              method: req.method,
            }
            this.sendSocketNotification("REQUEST_COMING", requestObj)
            res.status(200).send({status: 200})
          } else {
            res.status(400).send({status: 400})
          }
        }
        
        this.expressApp.get("/YOUR_PATH/:subpath", process)
        this.expressApp.post("/YOUR_PATH/:subpath", process) // when you need POST method.
        
        1 Reply Last reply Reply Quote 1
        • A Offline
          AxLed Module Developer
          last edited by Mar 30, 2020, 7:58 PM

          @sdetweil
          @Sean
          Thanks for your quick response, you are faster than my programming timeslots in my “mancave” are. Today i had some time and got it working.

          I will test my module changes (for MMM-Navigate) on my mirror for some days, maybe i find some errors and can fix them before i upload it to quick to github in a poor “quality”.

          My intension was to get rid of MMM-Remote-Control in my installation, as i found errors (while a new install of my MM) and as it seems that MMM-Remote-Control is not maintainanced anymore.

          I added following features to MMM-Navigate:

          • Raspberry operations: any Shellcommands, i use it for
            • restart of MM (pm2 restart mm)
            • restart of Raspberry (sudo shutdown -h now)
            • reboot of Raspberry (sudo reboot)
          • controlling MM by URL Calls (if you dont have a rotary encoder connected or while programming)

          stay healthy

          Regards

          AxLED

          1 Reply Last reply Reply Quote 2
          • A Offline
            AxLed Module Developer
            last edited by Apr 9, 2020, 6:06 PM

            Hi,

            testing completed, today i uploaded new release to github.
            MMM-Navigate - V1.3 released

            Regards

            AxLED

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