hassio-addons / addon-bookstack

Bookstack - Home Assistant Community Add-ons
https://addons.community
MIT License
55 stars 13 forks source link

Feature Request: Tighter intergation way (kind of ingress) #322

Closed rabits closed 1 month ago

rabits commented 1 month ago

Problem/Motivation

Spent quite a bit of time trying to integrate bookstack into home assistant with menu record and https nginx proxy

Expected behavior

Probably there is a way to setup it by default the way it will properly redirect even the uploaded images through home assistant proxy and will be more stable and available from the remote proxy.

Actual behavior

For now there are 3 issues with this complicated setup:

  1. Works only with full path in APP_URL which limits the ability to use chained reverse proxies (one local proxy to serve HA via https and wifi connection and another remote proxy when you on a road)
  2. If I try to upload an image or switch the Light/Dark mode - it's not updating the iframe to show the changes (works well if I switch on https://ha.local/bookstack/)
  3. Many pages cached in different states, no cache disable helps

Steps to reproduce

  1. Install Bookstack addon as usual (with mariadb) + add the next envvars into:
    - name: APP_URL
    value: https://your-ha.local/bookstack  # In theory here should be something like "/bookstack", but it's not working so binding to local - so will be unavailable from remote proxy...
    - name: STORAGE_URL
    value: /bookstack_storage  # To make the upload of images/files bind to whatever domain you use
    - name: ALLOWED_IFRAME_HOSTS
    value: https://your-ha.local https://your-ha.remote.com
  2. Install & configure NGINX Home Assistant SSL proxy addon (when generate ssl certs make sure to use DNS-Altnames & add certs as trusted to android CA to use with companion app)
  3. Install Ingress addon through HACS & configure it to show the bookstack item in the HA menu: /config/configuration.yaml , reread it after update
    # Custom ingress menu fields
    ingress:
    wiki:
    work_mode: iframe  # Ingress shows no menu, so iframe helps here
    ui_mode: toolbar
    title: BookstackWiki
    icon: mdi:book
    url: /bookstack/
  4. Prepare new locations for nginx addon: /share/nginx_proxy_default_wiki_page.conf

    
    location /bookstack {
    rewrite /bookstack/bookstack_storage/(.*) /$1  break;
    rewrite /bookstack/(.*) /$1  break;
    
    proxy_pass http://a0d7b954-bookstack/;
    proxy_set_header Host $http_host;
    proxy_redirect http:// https://;
    proxy_http_version 1.1;
    
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Host $http_host;
    }

Special override for bookstack storage (images, etc...)

location /bookstack_storage { rewrite /bookstack_storage/(.*) /$1 break;

proxy_pass http://a0d7b954-bookstack/;
proxy_set_header Host $http_host;
proxy_redirect http:// https://;
proxy_http_version 1.1;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Host $http_host;

}


6. Restart nginx addon
7. Test how it's working - if you will upload picture it will be written to the database with `/bookstack_storage` prefix, which works for us just well.
illuzn commented 1 month ago

Did you read the documentation at all?

Ingress will not function due to the way the application stores image files.

rabits commented 1 month ago

@illuzn , documentation is for readers - I'm a writer and don't stop when letters are saying "something is impossible". And not quite sure you've got what I wrote in the description... With mentioned changes I was able to store images without hostname in the URL by setting STORAGE_URL variable (so instead of "https://host/path" now it uses "/path" for the images) - so the image storage is not an issue anymore. The rest of my findings you can locate in the description.

Anyway instead of spending time with altering bookstack I would recommend everyone who will look here to use Grocy - it's Equipment page is quite capable to store the local wiki content and works with HA ingress out of the box.