Local httpadmin access from http request node

I am creating a small http admin client. The client is implemented as a Node-Red flow. This works fine, but I have to manually configure the url of the http admin api. I would like to access the admin api of the same Node-Red engine as the flow runs in, so in principle I should not really have to manually enter the api url.

Passing in the url to the http request dynamically works fine, but is there some way to find out what the url should be using some existing node types? Is there any property on the RED object that could be used to retrieve the url? Can you get this information from inside a function node?

Not quite sure I follow?

As with any API, you need to know the endpoint in order to call it?

Perhaps a pseudo example and/or screenshots would clarify?

If you are writing a program to call services on the same host, you use the ’localhost’ as address, and do not need to configure any ip adress or DNS hostname. In the case of an http service you also need to know the port number and path to the service. The question is if you could pick up this information from the running Node-Red server - in order NOT to have to MANUALLY enter it.

Well you can set an env var for node-red port and also pick this env var up in the other program?

That would not help, you still would have to populate the information manually. The only context where this is known is inside the Node-Red server, so if it can not be retrieved from any api provided to the server nodes, then it could not be done.

Something somewhere has to be configured unless you are using a default install of Node-RED then localhost:1880 will be where you go to.

Still not 100% following...

Example of what ? Screenshots of what?

I think the question i pretty straightforward :

Is there an api provided to Node-Red nodes, where the node can ask for the url used for contacting the local http admin service, where local means the service of the Node-Red instance where the asking node resides ?

Clarification

When to Node-Red server is started, it gets its config regarding admin port number and path, from settings.js or elsewhere.

The question is if the server stores this information and makes it available via some api to the nodes within the server.

Honestly what you are asking is not clear to someone without your setup or details of knowledge or task at hand.

For example:

Are you talking about the node-red admin API or an API you have created in node-red using http-in nodes?

UPDATE (following your follow up post)

Unless you specify a port, it will be 1880. But if you do specify a different port (via start command or service or settings.js), do it via an env var, then your other application can use that.

Not that I recall, but you might get it from the Node-RED admin API for diagnostics but you'd still need to know the port and (maybe) the binding IP

There may be another way - like call an own API (hrtp-in~>http-reply) from within the node-red instance and inspect the req object, write that to somewhere on the file system or MQTT or DB or other common area for retrieval by other application.

Not got any screen time today to look into it for you. Someone else will probably pop in and have a better idea.

Honestly the context of my question requires no more understanding than:

  • a node-red ’server’ that provides its http admin api via a url (host, port, path)
  • a ’node’ running in the same server

Can this ’node’, via a javascript api, get the url (host, port, path) of the ’server’ ?

In case you know of a javascript api that provides this, I would like to know. If it does not exist, then I want to know that as well.

I don't think there is another application. I think the OP is attempting to access the admin api from within node red itself.

Correct :smiley:

That's much more clear. Thanks Colin.

@helander I don't know of (inside node-red flows) of a way. I know you can get this info via a plugin or custom node and then you'd be able to populate context or surface the values by some other means.

The values you'd want are httpAdminRoot, uiPort and uiHost and they'd be accessible in RED.settings (I think)

You can try a grabbing these in a function node but I'm fairly certain they won't be accessable.

Usin http nodes does not expose the http admin url, its port yes but not the path.

Is RED.settings an ”official” api, i.e. is it likely to be unchanged and available in future versions?

Only httpAdminRoot was available in RED.settings.

With path, port and host is missing but host is ’localhost’, so how do you find the port number? Maybe it is not available anywhere?

Without digging into the src, I would assume if it is not "something" it is gonna be the default (1880).

Do a test. Try firing up node-red with -p or --port set then see if it's has a value.

Do you mean that it would be found in RED.settings? If so, what property name?

I already use a non-standard port number and I can not find any property in RED.settings that have the port number in question.

One way to do this would be to specify, for example, the port in settings.js by putting at the start, before the exports line
process.env.MYPORT = 1881
and then lower down where the port is defined
uiPort: process.env.MYPORT,

Then the port will be available as the env variable MYPORT. Do the same for the path to make it available.

But that is MANUAL configuration and I could equally do that in my application.

Looking into the node-red code, it seems like the port number is just passed to the http server without node-red ever ”touching” it, so node-red is not aware of the port number, and as such there is no way for node-red to provide it to nodes.

I guess there is no Javascript to access the functionality exposed by the admin service (bypassing http)?