hassio-addons / addon-grocy

Grocy - Home Assistant Community Add-ons
https://addons.community
MIT License
319 stars 60 forks source link

Relative URL Problem #293

Closed birdwing closed 2 years ago

birdwing commented 2 years ago

Problem/Motivation

In attempting to "add as barcode to existing product" I am getting "This Page Does Not Exist" I am running the most recent 0.17.0 version

Expected behavior

It would take me to the page where I can add the barcode to a product.

Actual behavior

404 error

Steps to reproduce

Scan a barcode of a new product, then click the "add as barcode to existing product" button.

Proposed changes

When looking into the Network tab of the developer tools in Chrome I see this as the request URL https://ha.xxxxxxxxxxxx/api/hassio_ingress/Cgw705-rLHQ5aWiIXGHns62KpoLqe_bPwMNvRhGwydY//api/hassio_ingress/Cgw705-rLHQ5aWiIXGHns62KpoLqe_bPwMNvRhGwydY/purchase?flow=InplaceAddBarcodeToExistingProduct&barcode=123568& The Base URL appears to be getting duplicated.

birdwing commented 2 years ago

Here is the log output after a restart:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] 01-grocy: applying... 
[fix-attrs.d] 01-grocy: exited 0.
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: Grocy
 ERP beyond your fridge! A groceries & household management solution for your home
-----------------------------------------------------------
 Add-on version: 0.17.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 7.5  (amd64 / qemux86-64)
 Home Assistant Core: 2022.3.8
 Home Assistant Supervisor: 2022.03.5
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] grocy.sh: executing... 
[09:44:29] INFO: Patching Grocy to fix relative URL handling...
patching file views/layout/default.blade.php
[cont-init.d] grocy.sh: exited 0.
[cont-init.d] nginx.sh: executing... 
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] php-fpm.sh: executing... 
[cont-init.d] php-fpm.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[09:44:29] INFO: Starting PHP-FPM...
[09:44:31] INFO: Starting NGinx....
birdwing commented 2 years ago

The problem appears to be in the addon-grocy/grocy/rootfs/patches/fix_braindamage.patch file that the #284 PR patch brought in. Line 9 in that file appears to attempt to detect and fix when the BaseURL is duplicated. However, lines 10 and 11 make no sense

line 10: Grocy.BaseUrl = window.location.origin + '{{ $U('/') }}'; BaseURL will now include http(s)

line 11: Grocy.CurrentUrlRelative = "/" + window.location.pathname.replace(Grocy.BaseUrl, ""); The replace will never actually fire. Because BaseUrl contains http(s), but window.location.pathname pulls everything after the domain, and will not have http(s) in it.

Also, at least in chrome not sure if it's browser specific, window.location.pathname includes the leading '/'.

So "/" + window.location.pathname is what is causing the duplicate '//' in the url I first shared that was causing the 404. And the .replace() not firing at all is what I believe is causing the baseURL to be duplicated.

I'm wondering if line 11 is supposed to be: Grocy.CurrentUrlRelative = "/" + window.location.href.replace(Grocy.BaseUrl, ""); location.href instead of location.pathname.

birdwing commented 2 years ago

This problem only exists while using ingres. If I configure an web interface, it works fine without ingres.

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!