Laravel-Backpack / basset

Better asset helpers for Laravel apps.
MIT License
155 stars 11 forks source link

Format URL issue #131

Closed dauvray closed 1 month ago

dauvray commented 4 months ago

Hello,

I come back with this bug. It sometimes happens that when I make updates, the URL problem comes back.

I get this type on some URLs: https://domain.fr/var/www/laravel-project/vendor/backpack/crud/src/resources/assets/css/common.css?f811ef3ab2df

instead of: https://domain.fr/storage/basset/vendor/backpack/crud/src/resources/assets/js/common.css?f811ef3ab2df

So i checked BassetManager and i can see on line 160: if (! str_starts_with($asset, base_path()) && ! Str::isUrl($asset)) { ... }

As we can see, there is a management of the character string to ensure that it does not start with base_path()

But in my case the character string starts with base_path() and there is nothing that manages my case.

So on line 223, i change : $output && $this->output->write($asset, $attributes);

with: $output && $this->output->write('/storage/'.$path, $attributes);

This solves my problem. Maybe I'm doing something wrong but I can't see what.

when i dump(($asset) , i cleary see that base_path() is in the string.

jcastroa87 commented 4 months ago

Hello @dauvray

After make an update did you try to clean and create new basset cache?

php artisan basset:clear
php artisan basset:cache 

If you make a new deploy try with

php artisan basset:fresh

And finally check if there is any problem with config

php artisan basset:check

Let me know if thats work for you.

Cheers.

dauvray commented 4 months ago

php artisan basset:check give me:

Initializing basset check ..................................................................................................... DONE
Checking cache storage ........................................................................................................ DONE
Fetching a basset ............................................................................................................ ERROR

ERROR cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://domain.fr/storage/basset/vendor/backpack/basset/tests/Helpers/basset-test.js.

in fact I do not have a valid certificate on this project

Thanks

pxpm commented 4 months ago

Hey @dauvray

You may set in your .ENV BASSET_VERIFY_SSL_CERTIFICATE=false .

Would that help ?

dauvray commented 4 months ago

BASSET_VERIFY_SSL_CERTIFICATE=false

give

INFO Checking Backpack Basset installation.

Initializing basset check .................................................................................................. DONE
Checking cache storage ..................................................................................................... DONE
Fetching a basset .......................................................................................................... DONE

But same problem. Only my hack can save me ...

jcastroa87 commented 4 months ago

Hello @dauvray can you share "APP_URL" or any other setting you customiza about path.

Thanks.

dauvray commented 4 months ago

My app url is APP_URL=https://subdomain.domain.fr

pxpm commented 4 months ago

Thanks @dauvray I am working on other basset issues today, I hope I get to this issue too.

Unfortunatelly we cannot hardcode the "storage" part because that's project dependent. By default it's storage, but anyone can change it.

I will investigate this further 🙏

Thanks

nmalinoski commented 1 month ago

I was getting this issue as well, until I ensured that the web server could write to storage/app/public; making that writable causes the incorrect path behavior to clear up for me.

When I was poking around the BassetManager code, it seemed like the basset function was generating the correct paths and URLs; so, I'm thinking there's something about the cache directory not being writable causes the path generator to inappropriately insert the filesystem path into the output URL.

dauvray commented 1 month ago

seems to be ok