Read the statement by Michael Teeuw here.
How can i pass query / parameters from URL to module
-
Dear Developers,
i want to redesign one of my modules. Therefore i need a hint how i can make the following possible.
I want to pass a query / parameters from a module URL, f.e.
http://IPofMM:8080/MMM-Navigate/index?value1=xxx&value2=yyto my module.
What do i need?- a page in my module folder index.js(?)
- code do read the values of querystring and do something with it.
Maybe somebody can give me a tip how to do that or in which module it was already realized (except MMM-Remote-Control).
Regards
AxLED
-
@AxLed sorry. not quite sure what you mean…
u want to pass the info from where (how is the user presenting this info) to where
-
@sdetweil
User is presenting / entering datas by URL in his browser and module should be able to handle the datas.
AxLED -
@AxLed and did u setup an express path that invokes your node module function?
the url parms should be there
-
@sdetweil
No i didnt set any path so far, but express path seems to be the right search word and helps.
If i understood the documentation right, express path has to be located innode_helper.js.
But i still dont know how to move forward with this information.
Are there some modules which are using express path, where i can try to figure out how it works?Greetings
AxLED
I
-
@AxLed MMM-ImagesPhotos uses it…
the Module wants to use request, so issues a request to a local server (express path)
which invokes the routine to get the list of photos//(instead of doing the sendSocketNotification to the node_module…)
the express routine is like a cgi pgm invocation…
from
https://expressjs.com/en/guide/routing.htmlRoute parameters
the path can autoparse the url
Route path: /users/:userId/books/:bookId
Request URL: http://localhost:3000/users/34/books/8989
req.params: { “userId”: “34”, “bookId”: “8989” }but the result, net, is the parms are in the req (uest) parameter object when the routine is called
-
@sdetweil
Thanks for the response, it think now i have enough to read and i will try to get in up and running.I will give feedback within the next day.
AxLED
-
@AxLed cooll… standing by!
-
@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"); } -
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. -
@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
- Raspberry operations: any Shellcommands, i use it for
-
Hi,
testing completed, today i uploaded new release to github.
MMM-Navigate - V1.3 releasedRegards
AxLED
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login