Search code examples
phpcorslaravel-9filepond

Having cors problem with sub-sub domain to sub domain


Never understood what is the main problem with cors while I allow everything (use * on everything). I have stancl/tenancy, using singledb approach and have online dev server with username as subdomain as my working folder.

So I need to use second level sub domain as tenantOne . soix . example . com.

Anyway, I am using laravel splade package and it contains filepond package for file picker. Upload works good however when it prepends existing file to preview it is using first level subdomain as main domain from second sub domain as tenant. Which gets me this error:

Access to XMLHttpRequest at 'https://soix.example.com/storage/files/1/blog-posts/11/v7f80bOhp0bXWrkHMYiRTq5IHF9jw4doqSrtZFDA.jpg' from origin 'https://tenantOne.soix.example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

And my cors file contains:

'paths' => ['*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,

Any help here?

Tried allowing everything on cors and separately for each tenant, didn't work. (Ofc cleaning cache)


Solution

  • Currently, I found a workaround since I can't get cors to work at all:

    if (tenant()) {
        Config::set('filesystems.disks.public.url', route('tenant.index') . '/storage');
    }
    

    So it uses sub-domain as main URL