Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Node-RED root path ignored #41

Open
Neraud opened this issue Feb 19, 2018 · 7 comments
Open

Custom Node-RED root path ignored #41

Neraud opened this issue Feb 19, 2018 · 7 comments
Assignees
Labels

Comments

@Neraud
Copy link

Neraud commented Feb 19, 2018

Summary

When trying to run Node-RED with a custom root path, some 404 errors appear when editing a flow with homeassistant nodes.

The only visible symptom is that autocomplete is broken and a red "404" error is displayed at the top of the page.
Manually filling-in the inputs seems to work fine.

Steps to reproduce

Setup

I've started from scratch on a Debian stretch box, and installed both node-red and node-red-contrib-home-assistant via npm :

node-red@HomeTest:/opt/node-red$ node -v
v6.12.3
node-red@HomeTest:/opt/node-red$ npm -v
3.10.10
node-red@HomeTest:/opt/node-red$ npm list node-red
/opt/node-red
└── [email protected]

node-red@HomeTest:/opt/node-red$ npm list node-red-contrib-home-assistant
/opt/node-red
└── [email protected]

(I've stuck to [email protected] to avoid 3.0 issues that are already logged)

No custom root path

After the fresh install, custom root path are disabled in the settings.js :

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    //httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    //httpRoot: '/red',

And Node-RED listens on /

node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:00:34 - [info]

Welcome to Node-RED
===================

19 Feb 11:00:34 - [info] Node-RED version: v0.18.3
19 Feb 11:00:34 - [info] Node.js  version: v6.12.3
19 Feb 11:00:34 - [info] Linux 4.9.0-3-amd64 x64 LE
19 Feb 11:00:34 - [info] Loading palette nodes
19 Feb 11:00:35 - [warn] ------------------------------------------------------
19 Feb 11:00:35 - [warn] [node-red/rpi-gpio] Info : Ignoring Raspberry Pi specific node
19 Feb 11:00:35 - [warn] ------------------------------------------------------
19 Feb 11:00:35 - [info] Settings file  : /opt/node-red-data/settings.js
19 Feb 11:00:35 - [info] User directory : /opt/node-red-data
19 Feb 11:00:35 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
19 Feb 11:00:35 - [info] Flows file     : /opt/node-red-data/flows_HomeTest.json
19 Feb 11:00:35 - [info] Creating new flow file
19 Feb 11:00:35 - [info] Starting flows
19 Feb 11:00:35 - [info] Started flows
19 Feb 11:00:35 - [info] Server now running at http://127.0.0.1:1880/

When adding a simple Home Assistant Service node, an ajax call is sent to :
http://[domain]:1880/homeassistant/services
The autocomplete works fine.

Custom httpRoot

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    //httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    httpRoot: '/red',
node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:14:57 - [info]

Welcome to Node-RED
===================
[...]
19 Feb 11:14:58 - [info] Server now running at http://127.0.0.1:1880/red/

In the Node-RED admin, called with "/red", the Ajax calls are still sent to http://[domain]:1880/homeassistant/services
Which generates Cannot GET /homeassistant/services

However, if I add the root path manually, it answers correctly : http://[domain]:1880/red/homeassistant/services

Custom httpAdminRoot

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    //httpRoot: '/red',
node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:28:19 - [info]

Welcome to Node-RED
===================
[...]
19 Feb 11:28:19 - [info] Server now running at http://127.0.0.1:1880/admin/

In the Node-RED admin, called with "/admin", the Ajax calls are still sent to http://[domain]:1880/homeassistant/services
Which generates Cannot GET /homeassistant/services

However, if I add the root path manually, it answers correctly : http://[domain]:1880/admin/homeassistant/services

Workaround

I'm running NGinx as a Reverse Proxy. Adding a custom location to proxy to Node-RED works :

location /homeassistant/ {
	proxy_pass http://localhost:1880/red/homeassistant/;
	...
}

location /red/ {
	proxy_pass http://localhost:1880/red/;
	...
}
@AYapejian
Copy link
Owner

👍 for the awesomely detailed submission

I'll dig into this as soon as I have some time

@AYapejian AYapejian self-assigned this Feb 20, 2018
@AYapejian AYapejian added the bug label Feb 20, 2018
@Neraud
Copy link
Author

Neraud commented Feb 21, 2018

BTW, I've updated NodeJS and node-red-contrib-home-assistant, and have the same behavior :

node-red@HomeTest:/opt/node-red$ node -v
v8.9.4

node-red@HomeTest:/opt/node-red$ npm list node-red-contrib-home-assistant
/opt/node-red
└── [email protected]

@geek65535
Copy link

Thanks for the information. The workaround worked for me!

@elmexdechileen
Copy link

Awesome, thank you!

@oskapt
Copy link

oskapt commented Oct 14, 2018

For anyone running HAProxy instead of nginx, add this to the corresponding frontend or backend or listen section:

reqrep ^([^\ :]*)\ (/homeassistant/.*)     \1\ /admin/\2

(If you are using httpRoot instead of httpAdmin, replace admin with your the value of the httpRoot key from settings.js.)

@stuomas
Copy link

stuomas commented Dec 23, 2018

Would it be possible to post the complete workaround? Name/path of the file, and the whole file, or atleast the whole server {} section. There is enough room in the Internet :)

@oskapt
Copy link

oskapt commented Mar 12, 2019

@stuomas it depends on how your personal reverse proxy is configured. For me, I'm using HAProxy in front of a 3-node Kubernetes cluster where I'm running NodeRED. I'm rewriting the URL in the backend for that cluster:

backend bk_rancher_http
  balance source

  # rewrite requests for nr-hass HA entities
  # see https://github.com/AYapejian/node-red-contrib-home-assistant/issues/41
  reqrep ^([^\ :]*)\ (/homeassistant/.*)     \1\ /admin/\2

  server rancher01 10.68.0.40:80 check fall 3 rise 2
  server rancher02 10.68.0.36:80 check fall 3 rise 2
  server rancher03 10.68.0.37:80 check fall 3 rise 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants