rogerfar / rdt-client

Real-Debrid Client Proxy
MIT License
861 stars 111 forks source link

BasePath Issue #441

Open GameEnder opened 6 months ago

GameEnder commented 6 months ago

I have having a issue getting the BasePath setting to work. I have it set to "/rdt" in the appsettings.json and when I do nothing will show up anymore. Have cleared browser cache, and tried different browsers (Firefox and Chrome), Both never load the page is just blank and is not redirected to the login page.

This is on the Linux Service version inside of lxc container.

I can post the log but nothing shows up when I try an access the page.

j-cray commented 6 months ago

I'm facing the same issue under similar circumstances. It seems the BasePath setting is not having any effect. The service remains accessible from ip:port but not from ip:port/rdt or url.xyz/rdt. The logs show the following error (I don't know what the heck I'm doing so who knows if this is relevant):

2024-03-28 01:11:27.467 -07:00 [ERR] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HN2EVQG75LLH", Request id "0HN2EVQG75LLH:00000001": An unhandled exception was thrown by the application. System.InvalidOperationException: Writing to the response body is invalid for responses with status code 304. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Advance(Int32 bytes) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponsePipeWriter.Advance(Int32 bytes) at Microsoft.AspNetCore.Http.HttpResponseWritingExtensions.Write(HttpResponse response, String text, Encoding encoding) at Microsoft.AspNetCore.Http.HttpResponseWritingExtensions.WriteAsync(HttpResponse response, String text, Encoding encoding, CancellationToken cancellationToken) at RdtClient.Service.Middleware.BaseHrefMiddleware.InvokeAsync(HttpContext context) in C:\Projects\rdt-client\server\RdtClient.Service\Middleware\BaseHrefMiddleware.cs:line 42 at Program.<>c.<<<Main>$>b__0_14>d.MoveNext() in C:\Projects\rdt-client\server\RdtClient.Web\Program.cs:line 159

rogerfar commented 5 months ago

This should be fixed in the next version, feel free to comment if it's still broken.

GameEnder commented 5 months ago

It still dose not seem to be working. I just get a white page after setting the base path setting to anything other then null.

rogerfar commented 5 months ago

Can you check your browser console and see what that says?

GameEnder commented 5 months ago

This is the log on when I try and load the page:

GET
http://192.168.1.32:6500/rdclient/
[HTTP/1.1 304 Not Modified 2ms]

setting base href to /rdclient/ rdclient:14:19
Ruleset ignored due to bad selector. rdclient:1:1001
Unknown property ‘-moz-osx-font-smoothing’.  Declaration dropped. rdclient:1:1170
Error in parsing value for ‘-webkit-text-size-adjust’.  Declaration dropped. rdclient:1:1326
Unknown property ‘text-size-adjust’.  Declaration dropped. rdclient:1:1348
GET
http://192.168.1.32:6500/rdclient/runtime.52f1d05aa6c3afea.js

GET
http://192.168.1.32:6500/rdclient/main.95937d5411454d34.js

GET
http://192.168.1.32:6500/rdclient/polyfills.bc0070be939c8a90.js

Loading module from “http://192.168.1.32:6500/rdclient/polyfills.bc0070be939c8a90.js” was blocked because of a disallowed MIME type (“text/html”). rdclient
Loading module from “http://192.168.1.32:6500/rdclient/runtime.52f1d05aa6c3afea.js” was blocked because of a disallowed MIME type (“text/html”). rdclient
Loading module from “http://192.168.1.32:6500/rdclient/main.95937d5411454d34.js” was blocked because of a disallowed MIME type (“text/html”). rdclient
Loading failed for the module with source “http://192.168.1.32:6500/rdclient/polyfills.bc0070be939c8a90.js”. rdclient:23:146
Loading failed for the module with source “http://192.168.1.32:6500/rdclient/runtime.52f1d05aa6c3afea.js”. rdclient:23:69
Loading failed for the module with source “http://192.168.1.32:6500/rdclient/main.95937d5411454d34.js”. rdclient:23:218
GET
http://192.168.1.32:6500/rdclient/styles.e0d9d5dcd8df4190.css
[HTTP/1.1 200 OK 0ms]

GET
http://192.168.1.32:6500/rdclient/favicon.ico
[HTTP/1.1 200 OK 0ms]

The stylesheet http://192.168.1.32:6500/rdclient/styles.e0d9d5dcd8df4190.css was not loaded because its MIME type, “text/html”, is not “text/css”. rdclient
link-detect ON ! link-detector.js:42:13
got env 
Object { autoPopup: true, findPageLinks: true, displayIcons: true, findPageWhitelisted: true, findPageWhitelist: (10) […] }
link-detector.js:54:17

And this is my config:

{
  "Logging": {
    "File": {
      "Path": "/opt/rdtc/data/db/rdtclient.log",
      "FileSizeLimitBytes": 5242880,
      "MaxRollingFiles": 5
    }
  },
  "Database": {
    "Path": "/opt/rdtc/data/db/rdtclient.db"
  },
  "Port": "6500",
  "BasePath": "/rdclient"
}
j-cray commented 5 months ago

just tested this as well with the same result. here's what the chromium console offered up:

setting base href to /rdt/ runtime.52f1d05aa6c3afea.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. polyfills.bc0070be939c8a90.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. main.95937d5411454d34.js:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

I checked rdtclient.log and don't really see anything, but here it is just in case.

rogerfar commented 5 months ago

That usually means it's trying to load a JS file, but the server is returning plain HTML.

If you check the console tab, could you check the response part for a failed request:

image

j-cray commented 5 months ago

For sure. I wonder why it is trying to load a js file. Here is the response output:


<html lang="en" data-critters-container>
  <head>
    <meta charset="utf-8">
    <title>Real-Debrid Torrent Client</title>
    <base href="/rdt/">
    <script>
      (function () {
        var baseElement = document.querySelector("base");

        if (baseElement) {
          var hrefValue = baseElement.getAttribute("href");
          window["_app_base"] = hrefValue;
          console.log("setting base href to " + window["_app_base"]);
        }
      })();
    </script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="/rdt/favicon.ico">
  <style>:root{--fa-style-family-brands:"Font Awesome 6 Brands";--fa-font-brands:normal 400 1em/1 "Font Awesome 6 Brands"}@font-face{font-family:"Font Awesome 6 Brands";font-style:normal;font-weight:400;font-display:block;src:url(fa-brands-400.b6033b540dd66f84.woff2) format("woff2"),url(fa-brands-400.9a905705860d0777.ttf) format("truetype")}:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-regular:normal 400 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:400;font-display:block;src:url(fa-regular-400.3580b4a95c9bb1d5.woff2) format("woff2"),url(fa-regular-400.67a0fb748649533d.ttf) format("truetype")}:root{--fa-style-family-classic:"Font Awesome 6 Free";--fa-font-solid:normal 900 1em/1 "Font Awesome 6 Free"}@font-face{font-family:"Font Awesome 6 Free";font-style:normal;font-weight:900;font-display:block;src:url(fa-solid-900.fd0b155cd663a8fa.woff2) format("woff2"),url(fa-solid-900.6a8db53d80e9da0c.ttf) format("truetype")}@charset "UTF-8";html,body{margin:0;padding:0}html{box-sizing:border-box}*,*:before,*:after{box-sizing:inherit}html{background-color:#fff;font-size:16px;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;min-width:300px;overflow-x:hidden;overflow-y:scroll;text-rendering:optimizeLegibility;-webkit-text-size-adjust:100%;text-size-adjust:100%}body{font-family:BlinkMacSystemFont,-apple-system,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Helvetica,Arial,sans-serif}body{color:#4a4a4a;font-size:1em;font-weight:400;line-height:1.5}</style><link rel="stylesheet" href="/rdt/styles.e0d9d5dcd8df4190.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="/rdt/styles.e0d9d5dcd8df4190.css"></noscript></head>
  <body>
    <app-root></app-root>
  <script src="/rdt/runtime.52f1d05aa6c3afea.js" type="module"></script><script src="/rdt/polyfills.bc0070be939c8a90.js" type="module"></script><script src="/rdt/main.95937d5411454d34.js" type="module"></script></body>
</html>```
rogerfar commented 5 months ago

@j-cray and I assume that your appsettings.json still has the basepath set to /rdt right?

j-cray commented 5 months ago

Exactly. I've left it set for testing purposes here. I'm accessing rdt-client from ip:port/rdt so no reverse proxy is getting in the way or anything.

rogerfar commented 5 months ago

The odd thing is that it seems that the CSS files are loaded correctly right?

j-cray commented 5 months ago

Indeed! I can read the full stylesheet in the inspector, and I can see the style in the html file. So there are definitely signs of life, it's just not all loading in properly. A couple other small details I notice are that the title is correctly displayed on the tab, but the favicon isn't, not sure if that tells us anything.

imran0 commented 4 months ago

Did we ever get a fix for this? I too cannot get rdt working with a different base path url

Oorweeg commented 2 months ago

Just been trying to set this up myself but having the same issues as others reported here by the looks of it. Just loads a blank page 😢

rogerfar commented 2 months ago

What does your network tab in the developer console say? Does it try to load the correct JS and CSS files?

Oorweeg commented 2 months ago

What does your network tab in the developer console say? Does it try to load the correct JS and CSS files?

yes. I get the same issue as above where the .js files are blocked because they are tried to be loaded as the wrong MIME type text/HTML so I get a 200 for them but the size is 0Bytes.

issues-guy commented 2 months ago

Running the docker container and after setting BASE_PATH to /rdt-client just getting a white page when opening in browser

nickkitto commented 1 month ago

I am having the same issue. Set the base path to /rdt inside the appsettings.json file and restart the app.

With or without the base path changed, the js/css are served under the root, ie it is always under http://localhost:6500/runtime.52f1d05aa6c3afea.js

Base path Attempted path Result
http://localhost:6500/runtime.52f1d05aa6c3afea.js Success
/rdt http://localhost:6500/rdt/runtime.52f1d05aa6c3afea.js Failure

When hitting an non valid url it is returning the index page which cannot be parsed as css/js.

image

image

rogerfar commented 1 month ago

@nickkitto how are you using rdt? I'm having troubles reproducing this.

nickkitto commented 1 month ago

I am on Windows 11.

I just reran these steps:

The same issue occurs for me when running as a service. I have also tried rdt and /rdt/ as the base path. It also occurs if I set the env var BASE_PATH and have nothing in the appsettings.json

I also tried running it via the source, had the same issue (just copied wwwroot into the RdtClient.Web folder). Will see if I can figure anything else for you.

rogerfar commented 1 month ago

Ok I see, that's a very different usecase. The BasePath options are just informing RDT that it can expect to be served from there, usually when it's used with a reverse-proxy. When launching RDT, it's using the kestrel server, but it's not configuring the base path on kestrel.

nickkitto commented 1 month ago

In Program.cs, I added app.UsePathBase($"/{basePath.TrimStart('/').TrimEnd('/')}/"); and it works as per my expectation. I can make a PR, but I am a little unsure of your usecase and whether this affects it, and hence whether you would add this under a different flag etc.

I am reverse proxying (maybe I am mixing up the type?) through IIS, with other apps (sonarr, radarr, nzbhydra, sabnzbd, prowlarr). I just have a rewrite rule like so

<rule name="RDT" stopProcessing="true">
    <match url="^rdt(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="http://localhost:6500/rdt{R:1}" />
</rule>

Having a quick look at radarr/sonarr source code since they are also using a similar backend stack, they set this setting as above, and have it labelled as URL Base in their configuration. I would assume others like me thought it was similar based on this.

rogerfar commented 1 month ago

I can add app.UsePathBase($"/{basePath.TrimStart('/').TrimEnd('/')}/"); and see if that helps.

I used your example and without it, it also works for me.

Try running the project in Visual Studio as the IIS Express profile, that one is configured to use the BASE_PATH env variable.

nickkitto commented 1 month ago

Running it via IIS Express does work fine.

I believe in launchsettings.json you have set applicationUrl to also have test. I think that when this is hosted by IIS Express it will serve it all under here, hence why it is working as expected when running with the IIS Express profile.

The UsePathBase seems like it will do the same thing under kestrel. This would make it work perfectly for me and I imagine others.

Oorweeg commented 1 month ago

Basepath is working now for me with 2.0.86 in docker on Linux behind Nginx reverse proxy

nickkitto commented 1 month ago

I updated to 2.0.86 and the compiled version works great for me too. Thanks for the quick turnaround Roger!

GameEnder commented 1 month ago

Not working still in the non docker version.

Edit: Never mind. Helps if you save the config file.