Shared URL Parameters

Not experienced with Node Red and need help doing something which is probably very easy but looks like Mt Everest to me. Want to use browser(s) working locally in Windows 10 local PC that has fields where multiple URL parameters can be filled in:

FOO = 123456

BAR = abc

Then, write URLs with those variables and have them work the same in a browser:

webpage1 dot com/?var1=FOO&var2=BAR
would send
webpage1 dot com/?var1=123456&var2=abc

webpage2 , webpage3, etc would use same variables. If I update the fields in a local webpage and refresh browser, would like the new value(s) to be used instead.

Can Node Red be used to do this? Maybe need to implement on a small, inexpensive local web server/"router" (or in the cloud) to modify external addresses sent out with common URL parameters? Not sure?

Any help with this greatly appreciated.

This example flow should get you started:

Some explanation;

This will create 2 http endpoints.

The first url: http://<your-node-red-ip>:1880/set_variables
This will present 2 input fields (foo and bar), once you fill it in and submit it, it will store the information into a flow variable.

To get redirected: http://<your-node-red-ip>:1880/get_variables?var1=foo&var2=bar (ie matching the fieldnames), it will redirect you to http://website1.com/?var1=abc1234&var2=dslksh (with the values coming from the variables).

Check the function node to see what is happening, as a location header will be set based on the variables.

The flow

[{"id":"2fe7755f.ceb28a","type":"group","z":"a261cacc.0688a","name":"Input form","style":{"label":true},"nodes":["2b82e158.61f07e","8d0b04a8.542d1","ce233bee.f9717","dd2afb80.8b6ff8"],"x":118,"y":199,"w":600,"h":130},{"id":"2b82e158.61f07e","type":"http in","z":"a261cacc.0688a","g":"2fe7755f.ceb28a","name":"","url":"/set_variables","method":"get","upload":false,"swaggerDoc":"","x":234,"y":264,"wires":[["ce233bee.f9717"]]},{"id":"8d0b04a8.542d1","type":"http response","z":"a261cacc.0688a","g":"2fe7755f.ceb28a","name":"","statusCode":"","headers":{},"x":602,"y":240,"wires":[]},{"id":"ce233bee.f9717","type":"template","z":"a261cacc.0688a","g":"2fe7755f.ceb28a","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<html>\n    <body>\n        <form method=\"GET\" >\n            FOO:<input type=\"text\" name=\"foo\" /><br/>\n            BAR:<input type=\"text\" name=\"bar\" /><br/>\n            <input type=\"submit\"/>\n        </form>\n    </body>\n</html>","output":"str","x":420,"y":264,"wires":[["8d0b04a8.542d1","dd2afb80.8b6ff8"]]},{"id":"dd2afb80.8b6ff8","type":"change","z":"a261cacc.0688a","g":"2fe7755f.ceb28a","name":"set variables","rules":[{"t":"set","p":"params","pt":"flow","to":"req.query","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":622,"y":288,"wires":[[]]},{"id":"ac4de379.e58378","type":"group","z":"a261cacc.0688a","name":"Redirect","style":{"label":true},"nodes":["a95c6fa3.9cf068","2c549988.b846c6","4ca276aa.78cab","3999e6d6.8d29fa"],"x":118,"y":367,"w":604,"h":130},{"id":"a95c6fa3.9cf068","type":"http in","z":"a261cacc.0688a","g":"ac4de379.e58378","name":"","url":"/get_variables","method":"get","upload":false,"swaggerDoc":"","x":234,"y":408,"wires":[["2c549988.b846c6"]]},{"id":"2c549988.b846c6","type":"function","z":"a261cacc.0688a","g":"ac4de379.e58378","name":"","func":"req = msg.req.query\n\nvar1= flow.get(\"params\")[req.var1];\nvar2 = flow.get(\"params\")[req.var2];\n\nurl = \"website1.com/?var1=\"+var1+\"&var2=\"+var2\nmsg.headers = {}\nmsg.headers['Location'] = url\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":408,"wires":[["4ca276aa.78cab","3999e6d6.8d29fa"]]},{"id":"4ca276aa.78cab","type":"http response","z":"a261cacc.0688a","g":"ac4de379.e58378","name":"","statusCode":"302","headers":{},"x":636,"y":408,"wires":[]},{"id":"3999e6d6.8d29fa","type":"debug","z":"a261cacc.0688a","g":"ac4de379.e58378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":626,"y":456,"wires":[]}]
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.