How could I get the host url in Node-Red?

2,037 views
Skip to first unread message

Kulasangar Gowrisangar

unread,
Mar 21, 2017, 1:15:38 PM3/21/17
to Node-RED
Is it possible to get the host url and the protocol from the server side (ie: any node js file) ?

For example, let's say the node-red is running on http://localhost:1880, I need to get the protocol (http) and the host(localhost:1880). 

I was able to get it from the client side by using window.location.host and window.location.protocol, but then not sure how could I get it in my js?

Thanks!

Nick O'Leary

unread,
Mar 21, 2017, 1:22:20 PM3/21/17
to Node-RED Mailing List
Hi,

Via your settings file, you'll see RED.settings.uiPort and RED.settings.uiHost are used to set what port and interface node-red listens on. However that won't necessarily tell you what external IP address is used to access the instance; the default value of 0.0.0.0 means it listens on all interfaces.

So you would have to add a custom setting to the settings object in settings.js to hold that information.



Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/b83322a7-26df-4647-b0da-3764e0b7d16f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick O'Leary

unread,
Mar 21, 2017, 1:28:57 PM3/21/17
to Node-RED Mailing List

That is now the fourth time you've posted the same question here and on stack Overflow at the same time.

http://stackoverflow.com/questions/42934063/how-could-i-get-the-host-and-protocol-in-node-red


On Tue, 21 Mar 2017, 17:22 Nick O'Leary, <nick....@gmail.com> wrote:
Hi,

Via your settings file, you'll see RED.settings.uiPort and RED.settings.uiHost are used to set what port and interface node-red listens on. However that won't necessarily tell you what external IP address is used to access the instance; the default value of 0.0.0.0 means it listens on all interfaces.

So you would have to add a custom setting to the settings object in settings.js to hold that information.



Nick
On 21 March 2017 at 17:15, Kulasangar Gowrisangar <kulasa...@gmail.com> wrote:
Is it possible to get the host url and the protocol from the server side (ie: any node js file) ?

For example, let's say the node-red is running on http://localhost:1880, I need to get the protocol (http) and the host(localhost:1880). 

I was able to get it from the client side by using window.location.host and window.location.protocol, but then not sure how could I get it in my js?

Thanks!

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Kulasangar Gowrisangar

unread,
Mar 21, 2017, 1:41:05 PM3/21/17
to Node-RED

Oops sorry @Nick, I have done it the other way round, from what you mentioned:

And if you continue to cross post the same question to both here and Stack Overflow, please at least include a link to the SO post here so you don't duplicate efforts in trying to help you.

I'll post the SO link here the next time. Sorry about that again.

So you would have to add a custom setting to the settings object in settings.js to hold that information.

Hence I can't dynamically identify the host without holding the info in the settings.js? 

Thanks Nick!

Kulasangar Gowrisangar

unread,
Mar 21, 2017, 2:06:28 PM3/21/17
to Node-RED
I tried accessing it as RED.settings.uiHost in my index.js, but it throws RED as undefined! Should I be importing it as:

module.exports = function(RED){}



On Tuesday, March 21, 2017 at 10:45:38 PM UTC+5:30, Kulasangar Gowrisangar wrote:

Ben Hardill

unread,
Mar 21, 2017, 9:07:36 PM3/21/17
to Node-RED
I answered the host part for you last week on StackOverflow and gave you all the code you need to build a link back to the running instance of node-red.

http://stackoverflow.com/questions/42786793/how-to-get-the-base-url-in-node-red
Reply all
Reply to author
Forward
0 new messages