Nextcloud - UnRaid - Nginx Proxy Manager - CORS settings errors w/ Nextcloud FilePicker addon for Foundry

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 29.0.5): Nextcloud Hub 8 (29.0.4)
Operating system and version (eg, Ubuntu 24.04): Linux 6.1.99-Unraid x86_64
Apache or nginx version (eg, Apache 2.4.25): Docker:latest - 8.2-apache I think
PHP version (eg, 8.3): 8.2.22

This is my problem :

I have my UnRaid server with a Foundry Virtual Tabletop, Nextcloud and Nginx proxy manager docker on it.

Foundry can be accessed via toto.ch
Nextcloud via drive.yoda.ch

I would like to use an addon for Foundry called Nextcloud FilePicker. It makes my nextcloud file directly accessible from Foundry (GitHub - Daxiongmao87/nextcloud-filepicker)

If I follow the configuration instruction I also need the WebAppPassword app on Nextcloud, and add toto.ch to WebDAV/CalDAV and Files sharing API on it.
I also need to go on my Nginx proxy manager and add a custom location at “/” and add this :

if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' 'https://toto.ch';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PROPFIND, SEARCH, MKCOL, PUT';
        # Add any other required headers for your setup
        add_header 'Access-Control-Allow-Headers' 'Authorization, OCS-APIRequest, Content-Type';
        add_header 'Access-Control-Allow-Credentials' 'true';
        return 204;
    }

Now if I go on Foundry I can go on Playlists for example, create one, create a sound, In Audio Source select Nextcloud Data and search for my file.
The public link is added to the Source (https://drive.yoda.ch/s/gp4Z7r24aiP3Mbn/download/99%2520-%2520Autre%252FIntro.mp3) but if I want now to play this sound I get this error :

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://drive.yoda.ch/s/gp4Z7r24aiP3Mbn/download/99%2520-%2520Autre%252FIntro.mp3. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 206.

I have tried multiple solution be I never can get both (add and use files) to work at the same time.

Can anyone help me please, I’m out of ideas…

For anyone passing by here was my solution :

In Nginx Proxy Manager add a custom location “/” to your Nextcloud domain with this :

if ($request_method = 'OPTIONS')
{
  add_header 'Access-Control-Allow-Origin' '*';
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PROPFIND, SEARCH, MKCOL, PUT';
  add_header 'Access-Control-Allow-Headers' 'Authorization,OCS-APIRequest,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  add_header 'Access-Control-Max-Age' 1728000;
  add_header 'Content-Type' 'text/plain; charset=utf-8';
  add_header 'Content-Length' 0;
  add_header 'Access-Control-Allow-Credentials' 'true';
  return 204;
}
if ($request_method = 'POST')
{
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PROPFIND, SEARCH, MKCOL, PUT' always;
  add_header 'Access-Control-Allow-Headers' 'Authorization,OCS-APIRequest,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  add_header 'Access-Control-Allow-Credentials' 'true' always;
}
if ($request_method = 'GET') {
  add_header 'Access-Control-Allow-Origin' '*' always;
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PROPFIND, SEARCH, MKCOL, PUT' always;
  add_header 'Access-Control-Allow-Headers' 'Authorization,OCS-APIRequest,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
  add_header 'Access-Control-Allow-Credentials' 'true' always;
}

In Nextcloud add in your WebAppPassword under WebDAV/CalDAV AND Files sharing API the full domain name (https://yoda.com) of your Foundry Virtual Tabletop.

You will still have CORS errors but everything will work now !