Laravel-Backpack / basset

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

With Laravel, can I serve file without symlink or copy to /public ? #104

Closed realtebo closed 10 months ago

realtebo commented 10 months ago

We are forced to do a release on a shared host.

No symlink so.

So we must recreate public/storage/basset/etc etc folders.. and re-release

Can we setup basset to internalize files automatically even in production ? And / or to store in pubic/storage/basset etc.. at first use even in production ?

hagealex commented 10 months ago

I might have a smiliar issue. I run my application (Backpack 6) on Scalingo.

On localhost everything works fine. But in production the basset files aren't loaded:

Although I'm able to setup symlinks they don't seem to work. Event though I can see that there is a folder basset within storage/app/public all requests to these files return a 404 error.

My app config looks like this:

APP_URL=https://portal.kultouri.de
APP_ENV=production
BASSET_DEV_MODE=false
FILESYSTEM_DRIVER=public

The symlink and basset files were generated: grafik

grafik

This is an example request: https://portal.kultouri.de/storage/basset/vendor/backpack/theme-coreuiv4/resources/assets/css/coreui4.css?a764a292af3e=

hagealex commented 10 months ago

Update: I was able to "fix" my problem with this workaround:

In the post-install-cmd of the composer.json I run this: "mv storage/app/public/basset/* public/storage/basset/".

I move the basset files directly into the storage folder. I know it's just a workaround but for the moment it does what I need.

Could it be an option for the future to be able to move the basset files directly into a specified folder in /public ?

UPDATE: As mentioned in #103 some files are generated after the deployment on first page load. So my workaround isn't really working.

pxpm commented 10 months ago

@hagealex basset should use whatever disk is defined, by default it's public.

In case you modified the default public disk, we ship with a basset disk that is a copy of the default Laravel public disk, you can try using the BASSET_DISK=basset in your .env file. https://github.com/Laravel-Backpack/basset/blob/224e9ed08bf0fa0b96397f163fb1c2301dde8cc9/src/BassetServiceProvider.php#L185

I am not sure what does your FILESYSTEM_DRIVER config does, or if it may have something to do about the issue, I couldn't find any mention of it in the Laravel docs https://laravel.com/docs/10.x/filesystem

Also a php artisan basset:check may help to debug if basset() is having any issues.

@realtebo I think your solution lies close to the @hagealex, use a custom disk that points to the public folder, that way you don't need a storage:link to.

// in config/filesystems.php add a new custom disk:
'custom_disk' => [
            'driver'     => 'local',
            'root'       => public_path('assets'),
            'url'        => env('APP_URL').'/assets',
            'visibility' => 'public',
            'throw'      => false,
        ],

// in your .env
BASSET_DISK=custom_disk

Without any storage link, it will just work: image

Basset is just a "scrapper" that saves the results in a disk. How you configure and what disk to use is up to you.

Let me know if I didn't make myself clear I can try to better explain what I meant if that's the case 🙏

Cheers

hagealex commented 10 months ago

@pxpm Thank you for your explanation! I'll try this out when I'm back home and give you feedback on this.

hagealex commented 10 months ago

@pxpm Your suggestion works perfect for me. Thank you so much!

So basically the issue was my misunderstanding of how the Laravel Filesystem works. Thanks for clarification!

pxpm commented 10 months ago

@pxpm Your suggestion works perfect for me. Thank you so much!

So basically the issue was my misunderstanding of how the Laravel Filesystem works. Thanks for clarification!

You're welcome. Glad I could help. 🙏

promatik commented 10 months ago

As @pxpm said, Basset can use any disk defined by the developer 👌 so no need for symlinks if the the developer can't use them. I'll close this one for now.