How to use X-Ingress-Path in an add-on?

In the development docs about the addons at Presenting your addon | Home Assistant Developer Docs (home-assistant.io), you can read the following

If the application doesn’t support relative paths or you can’t set a base url, you can use nginx filter to replace the URL with correct path. Ingress adds a request header X-Ingress-Path that can be used.

Can someone explain and/or give an example how to do that?

This has seemingly not been used much yet.
No one who has an idea?

Hi @evb,
Stumbled across the same line in the manual as you did, just a few days ago.
Honestly, I was happy the moment I figured out another issue, as this line of information was not at all useful to me. (And also not applicable to my project.)

Doing just a quick search on GitHub it looks the described request header is not used that often:

In case you find an answer, please don’t forget to share the knowledge. :grimacing: :pray:

Some days ago I was fighting with the same question as I had to write a dedicated proxy (using nodejs) for an HA add-on I am currently developing. See here for a working proxy implementation which uses http-proxy-middleware to modify the response, adding the corresponding X-Ingress-Path.

See here for more actual implementation of the ha-proxy I have written:

Hopefully you can grab the information you need to understand the implications of using X-Ingress-Path correctly.

@jens-maus, I’m using nginx, so don’t know, but thanks anyway.

Meanwhile I found this on github
zwavejs2mqtt/reverse-proxy.md at 91eef10f24c6568aefd51aad5c77f7e771d8eb53 · zwave-js/zwavejs2mqtt (github.com)

Using an HTTP header
You can pass the external path by setting the X-External-Path header, for example suppose you had the following nginx configuration:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 9000 default_server;
    listen [::]:9000 default_server;

    location /hassio/ingress/ {
        proxy_pass http://localhost:8091/;
        proxy_set_header X-External-Path /hassio/ingress;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}
This will tell the application to serve the application and relevant elements under /hassio/ingress/.

In case you are using the ingress of Home Assistant you will want to pick up the X-Ingress-Path; and map it, something along these lines:

  proxy_set_header X-External-Path $http_x_ingress_path;

I imagine it is specific for the zwavejstomqtt add-on?, but it gives already an idea, I think.

Now it’s time to read (again) the nginx docs and try to map this…

Did anyone figure this out? I’m trying to add a node.js addon that doesn’t play well with ingress. It works fine behind nginx but I cannot get it working behind the ingress path.

I am using the content of that header in some rewrite rules in my add-on “ingress-proxy”: https://github.com/tux2000/home-assistant-addons/blob/21e1402a63dd264ff55f5f37d0881378a0d8b332/ingress-proxy/rootfs/etc/nginx/templates/direct.gtpl

The header basically contains the ingress specific part of the url including the key as well and is exposed as variable in nginx

This is awesome and worked for an addon I could not get to ingress due to non-relative paths! Be awesome to have a menu or multiple subdirectories to point to different destinations

@jens-maus

I’ve created an addon to be able to have one central instance of Cura Ultimaker amongst all my devices, by having it run as an HA addon. From my testing thus far, it works well, but only by directly connecting to it in your browser via ip:port. I’m trying to get the ingress to work so that it can be accessed remotely through home assistant, though I’m only able to reach the novnc page- after that it returns a 404: not found.

Does anyone know how I can get the ingress to work properly?

@raddacle
I have excactly the same problem.
Have you solved your problem and how?