linuxserver / docker-nextcloud

GNU General Public License v3.0
677 stars 128 forks source link

[BUG] JavaScript loading issue #410

Closed ahavriluk closed 2 months ago

ahavriluk commented 5 months ago

Is there an existing issue for this?

Current Behavior

Loading JavaScript produces error in browser console:

Refused to execute script from 'https://REDACTED/login/selectchallenge?redirect_url=/js/core/merged-template-prepend.js?v%3D4c410a93-0' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

This issue has beed addressed lately resulting in multiple commits but it is still not fixed. I am running the latest image in Uraid OS in a docker container.

Expected Behavior

No response

Steps To Reproduce

  1. Two-way authentication app is enabled
  2. Login with username/password without MFA setup yet
  3. Select "Setup two-factor authentication" button

Environment

- OS: Unraid
- How docker service was installed: Using nextcloud template and image from lscr.io/linuxserver/nextcloud

CPU architecture

x86-64

Docker creation

irelavant

Container logs

text  error  warn  system  array  login  

https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
github-actions[bot] commented 5 months ago

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

teambvd commented 5 months ago

This isn't an issue with the LSIO nextcloud image (LSIO packaging of the application), but one you're experiencing with the twofactor_totp nextcloud app - I'd recommend taking a look at the TOTP app repo for assistance on this one.

Quick search there pulls up a couple hits, including this one; just noting as it might be helpful - asking there would be your best bet.

ahavriluk commented 5 months ago

Thank you! I have moved to nextcloud-aio image and the issue doesn't exist there using the same TOTP.

joomlaproffs commented 5 months ago

I have this exact issue as @ahavriluk explains in first post. I am not using the TOTP plugin at all (it's disabled).

Screenshot 2024-01-24 082617

This is a new fresh install.

Also sharing a folder from the browser does not work as the sidebar just loads forever. Might be related to above issue.

image

Everything seems to work nice from Android app.

JcMinarro commented 5 months ago

I have the same issue when sharing a folder and I already reported https://github.com/nextcloud/server/issues/43049 It looks like for some reason the file /js/core/merged-template-prepend.js doesn't exist

ahavriluk commented 5 months ago

I have the same issue when sharing a folder and I already reported nextcloud/server#43049 It looks like for some reason the file /js/core/merged-template-prepend.js doesn't exist

The file definitely exist in my case. If you examine the latest PRs, they were messing up with js and mime types. Somethings to look at since it is not working. I am pretty positive it is the image packaging related issue, since other images like nextcloud-aio don't have this problem.

DivineDominion commented 4 months ago

Update 2024-02-04: The ''''fix''''' I propose makes other things worse, retracted

old reply I found a way to modify the `default.conf` to try to load from Nextcloud's appdata/js directory. I hard-coded my instance id here, `appdata_och3cf62rsmv`, and the two step fallback that works thus far is this: ``` # Serve static files location ~* \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ { try_files $uri $uri/ @fallback; add_header Cache-Control "public, max-age=15778463, $asset_immutable"; access_log off; # Optional: Don't log access to assets location ~ \.wasm$ { default_type application/wasm; } } # Custom fallback logic location @fallback { # Handle JS files location ~* \.js$ { try_files /data/appdata_och3cf62rsmv/js/$uri /index.php$request_uri =404; } # Handle CSS files location ~* \.css$ { try_files /data/appdata_och3cf62rsmv/css/$uri /index.php$request_uri =404; } # Fallback for other file types (you could extend this concept as needed) location ~* \.(?:mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ { try_files /index.php$request_uri =404; } } ``` If lookup of the file fails, it tries to map e.g. the missing `/core/merged-template-prepend.js` to `/data/appdata_och3cf62rsmv/js/core/merged-template-prepend.js`. The sidebar now loads just fine. But this weird hack doesn't seem like it's really doing what it is supposed to do.
joshtrichards commented 4 months ago

@DivineDominion What did you default.conf look like before that? Because the try_files line doesn't look right. The one in the repo here looks more reasonable relative to what we document[1].

https://github.com/linuxserver/docker-nextcloud/blob/9e19c87fb6fe9e30f997de86bbc2a997d628f41e/root/defaults/nginx/site-confs/default.conf.sample#L136-L146

[1] https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html

DivineDominion commented 4 months ago

I take everything back -- after a day the Nextcloud nginx serves Bad Request errors :)

@joshtrichards I used the current one on master as reference.

Wanted to get double fallbacks. Got the syntax wrong it seems

LinuxServer-CI commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

johnsanc314 commented 3 months ago

I know this is closed, but I also had this same issue with the missing /js/core/merged-template-prepend.js file. After some tinkering with the requests, I noticed that /index.php/js/core/merged-template-prepend.js returns the file just fine.

I looked closer at my default.conf nginx config, and noticed I had this:

    # Serve static files
    location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }

        location ~ \.js$ {
            default_type text/javascript;
        }

        location ~ \.mjs$ {
            default_type text/javascript;
        }
    }

The culprit seemed to be this part:

        location ~ \.js$ {
            default_type text/javascript;
        }

Once I removed that, everything worked just fine and the file was accessible without index.php

After looking closer at the response headers for that file I see its set to application/javascript instead of the correct text/javascript

homerr commented 3 months ago

Just had a look and that block isn't in our default config in the container, is yours using a current default.conf or is it custom/outdated?

homerr commented 2 months ago

Going to close this off - there's been quite a few bugs in the 28 release of NC that have been slowly weeded out, with a few changes of our own mixed in (and reversed) I suspect this is OK now. Make sure you're using the most up to date versions of the default.conf file in the container.

Reopen if issues are still there!