F
Filament2d ago
BB

Overwrite asset_url from tenant middleware?

Is it possible to overwrite the config urls, so I can avoid cors errors? So far I tried this, but I assume tenantMiddleware is called too late or something else?
public function handle(Request $request, Closure $next): Response
{
/* @var \App\Models\Bakery $tenant */
$tenant = Filament::getTenant();

config()->set('app.url', 'https://'.$tenant->domain);
config()->set('app.asset_url', 'https://'.$tenant->domain);
config()->set('filesystems.disks.public.url', 'https://'.$tenant->domain.'/storage');

return $next($request);
}
public function handle(Request $request, Closure $next): Response
{
/* @var \App\Models\Bakery $tenant */
$tenant = Filament::getTenant();

config()->set('app.url', 'https://'.$tenant->domain);
config()->set('app.asset_url', 'https://'.$tenant->domain);
config()->set('filesystems.disks.public.url', 'https://'.$tenant->domain.'/storage');

return $next($request);
}
6 Replies
BB
BBOP2d ago
Just to clerify the main issue with this comes from when I use FileUpload and the image fails to load due to CORS.
toeknee
toeknee2d ago
You can set the config in the tenant middleware so say:
$tenant = Filament::getTenant();
$panel = \Filament\Facades\Filament::getPanel();
$tenant = Filament::getTenant();
$panel = \Filament\Facades\Filament::getPanel();
Then set the panel config here?
BB
BBOP2d ago
What am I supposed to set to the panel? I don't think i can do anything useful with it from what I can see
toeknee
toeknee2d ago
If you don't set the asset_url it should fallback to the current host are you not seeing that
BB
BBOP2d ago
from my manual test editing .env, livewire only cares about the APP_URL it never uses ASSET_URL but then again dumping the config in the resource returns the correct url, but livewire keeps using the env one im starting to think this is not filament issue but more livewire? Yeah, i will just move it to use the domain from $request so i can avoid using tenantMiddleware this seems to fix the issue and uses now the updated values
toeknee
toeknee2d ago
Great

Did you find this page helpful?