LukeChannings / moviematch

MovieMatch for Plex
Other
441 stars 26 forks source link

[Bug] 404 Not Found #52

Closed domesticwarlord86 closed 3 years ago

domesticwarlord86 commented 3 years ago

Describe the bug I'm using Docker to run this through a treafik reverse proxy. Checking the logs in Portainer, when I start the container I the logs get spammed with this

INFO Listening on port 8001 error: Uncaught (in promise) Error: <html><head><title>Not Found</title></head><body><h1>404 Not Found</h1></body></html> throw new Error(await req.text()) ^ at getSections (plex.ts:45:11) at async plex.ts:77:20

I had to change to 8001 port as CloudCMD uses port 8000.

I have tried various different plex server locations. https://plex.mydomain.com is accessible through anyone on the net and I tried this first. No luck. I tried http://localhost:32400, I've tried http://plex:32400/. All seem to give similar errors.

I attached a screen shot with my Domian and token truncated for more information.

To Reproduce Launch the program with docker compose. Check portainer logs, see this.

Desktop (please complete the following information):

Screenshot 2021-02-22 124147

LukeChannings commented 3 years ago

Hey @domesticwarlord86!

This seems like an issue specific to your setup, and might be pretty hard to debug (esp. without access to the environment).

  1. We need to figure out if Traefik needs an additional header for routing that MovieMatch isn't sending. Does curl https://plex.mydomain.com/library/sections?X-Plex-Token=$TOKEN return 404 if you run it elsewhere on your network?
  2. Can you get an interactive shell into the MovieMatch container and run the same command?

I don't know how experienced you are with this stuff, so let me know if you're unsure about anything.

domesticwarlord86 commented 3 years ago

Hey @domesticwarlord86!

This seems like an issue specific to your setup, and might be pretty hard to debug (esp. without access to the environment).

  1. We need to figure out if Traefik needs an additional header for routing that MovieMatch isn't sending. Does curl https://plex.mydomain.com/library/sections?X-Plex-Token=$TOKEN return 404 if you run it elsewhere on your network?
  2. Can you get an interactive shell into the MovieMatch container and run the same command?

I don't know how experienced you are with this stuff, so let me know if you're unsure about anything.

I'm not super experienced with this stuff, my only experience with Linux is this server but I've been running it for almost two years now so I've got a little bit of experience.

I only have ssh access to this box by the way. I was able to do the curl command from ssh, it returned a list of my Plex libraries, I'm guessing that's what's expected to happen.

In portainer there's a Console that will let me get access to inside the container, but it won't let me run that because it says the container hasn't started up completely. I'm guessing because of the errors. Any other ways you know to do a interactive shell for MovieMatch?

LukeChannings commented 3 years ago

Hey @domesticwarlord86 ,

So getting an interactive shell shouldn't be too difficult if you have SSH access to the Ubuntu server, and can run docker commands.

Here's what I do:

  1. Find out the container name / id for MovieMatch:
    λ docker ps -a | grep moviematch
    0de637f69153   lukechannings/moviematch        "/bin/deno run --all…"   2 minutes ago   Up 2 minutes   8000/tcp   nostalgic_greider
  2. Execute an interactive shell as root with: docker exec -it -u 0 nostalgic_greider /bin/bash
  3. Install curl (the image is pretty bare by default) with: apt-get update -y && apt-get install -y curl inetutils-ping bind9-dnsutils
  4. Run the curl command above and see if you an expected response

The command in 3 also installs ping and dig, for debugging routing and DNS. For example, to find the IP address resolved for plex.mydomain.com, you can dig plex.mydomain.com and look for the A record in the answer section.

domesticwarlord86 commented 3 years ago

@LukeChannings

So when I do the first command for docker I get two responses 93bdd37cb9ee lukechannings/moviematch "/bin/deno run --all…" 15 minutes ago Exited (1) 15 minutes ago silly_bassi eef6937b50cd lukechannings/moviematch:latest "/bin/deno run --all…" 18 hours ago Restarting (1) 57 seconds ago moviematch

The first one is going to be one I tried running just through docker commands a few minutes ago. The second one is the one that actually gets set up through treafik and everything. Either way, when I run the second command I get the following.

Error response from daemon: Container eef6937b50cd46feffb0e65bc1d4f8c70a1e7ba9e71f7c47be0b11093c31f568 is restarting, wait until the container is running Error response from daemon: Container 93bdd37cb9ee28cf1b1828c52e958de72668da6588afb99e6e232891c045eba1 is not running

LukeChannings commented 3 years ago

@domesticwarlord86

Ah, so the container is in a crashloop so you probably won't be able to get a shell into it (because it'll be killed before you can get anything done anyway).

What I usually do in these situations is replace the entrypoint for the container with sleep, so the container doesn't crash, but also doesn't start up MovieMatch. From there you can get a shell into the container and run curl, and maybe run moviematch manually for a quicker turn-around on tweaking the PLEX_URL.

Here's what I recommend:

This last command will start the moviematch image (creating a new container) and put you in an interactive shell.

You can run deno run -A --unstable ./src/index.ts to start Deno (you should do this to confirm you can reproduce the issue). After that you can follow the original advice on installing curl and testing connectivity to your Plex server.

domesticwarlord86 commented 3 years ago

@LukeChannings

Thank you so much for all your help by the way. Really appreciate you looking into this with me.

So I ran the following in SSH docker run --rm -u 0 e PLEX_URL=https://plex.XXXXXXXXX.info/ -e PLEX_TOKEN=XXXXXXXXXXXX -p 8001:8001 -it --entrypoint="/bin/bash" lukechannings/moviematch

And I get hit back with Unable to find image 'e:latest' locally docker: Error response from daemon: pull access denied for e, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'.

Any ideas what I'm doing wrong?

LukeChannings commented 3 years ago

@domesticwarlord86

You left off a - when you were editing the command:

- docker run --rm -u 0 e PLEX_URL=https://plex.XXXXXXXXX.info/ -e PLEX_TOKEN=XXXXXXXXXXXX -p 8001:8001 -it --entrypoint="/bin/bash" lukechannings/moviematch
+ docker run --rm -u 0 -e PLEX_URL=https://plex.XXXXXXXXX.info/ -e PLEX_TOKEN=XXXXXXXXXXXX -p 8001:8001 -it --entrypoint="/bin/bash" lukechannings/moviematch
domesticwarlord86 commented 3 years ago

@LukeChannings

Gotta love one little letter making you look bad lol.

Okay, with that I was able to get in. Installed curl as instructed and was able to successfully curl back to my server. It returned the list of libraries.

So that definitely means it's something up with treafik right? Since installing it this way would put it outside of treafik.

domesticwarlord86 commented 3 years ago

@LukeChannings

One last bit of info. I went and re-read your instructions and realized I had forgotten to do deno run -A --unstable ./src/index.ts so I went and did it, the second I did, it returned error: Uncaught (in promise) Error: <html><head><title>Not Found</title></head><body><h1>404 Not Found</h1></body></html> throw new Error(await req.text()) ^ at getSections (plex.ts:45:11) at async plex.ts:77:20

LukeChannings commented 3 years ago

@domesticwarlord86

Gotta love one little letter making you look bad lol.

No judgement here, we all make mistakes...

So that definitely means it's something up with treafik right? Since installing it this way would put it outside of treafik.

If curl didn't 404 this actually indicates there's something wrong with MovieMatch, since curl successfully makes the request, but MovieMatch fails.

I noticed you have a trailing / in your PLEX_URL (https://plex.XXXXXXXXX.info/), can you try it again without that trailing / (https://plex.XXXXXXXXX.info)?

Failing that, can you run:

export PLEX_URL="<PLEX URL>"
export PLEX_TOKEN="<PLEX Token>"

cat > test.ts << EOF
const req = await fetch(
`${PLEX_URL}/library/sections?X-Plex-Token=${PLEX_TOKEN}`,
{
    headers: { accept: 'application/json' },
}
)

console.log(await req.status(), await req.text())
EOF

deno run -A ./test.ts
domesticwarlord86 commented 3 years ago

@LukeChannings

I noticed you have a trailing / in your PLEX_URL (https://plex.XXXXXXXXX.info/), can you try it again without that trailing / (https://plex.XXXXXXXXX.info)?

Dude... it was the trailing /. I set it up through trafik without the trailing / and it works!

Screenshot 2021-02-23 082609

domesticwarlord86 commented 3 years ago

@LukeChannings

Maybe I spoke too soon. I put in a name, generated a room code and hit Engage and... nothing happens.

LukeChannings commented 3 years ago

@domesticwarlord86

I've added something to trim a trailing '/' from a Plex URL so this doesn't happen again.

Do you have any experience using devtools in Chrome? I'm happy to try to debug the WebSocket connection.

From what I've read Traefik should be able to reverse proxy WebSockets without any additional configuration, but I suspect the error lies there. I'm using haproxy for the same purpose and MovieMatch works out of the box.

domesticwarlord86 commented 3 years ago

@LukeChannings

I don't have much experience with the debug in chrome, but I'm happy to take directions.

Here's a screen shot of what's happening. The protainer logs just say INFO Listening on port 8000`.

Screenshot 2021-02-23 084823

LukeChannings commented 3 years ago

@domesticwarlord86

To open the console press Command+Option+J (Mac) or Control+Shift+J on everything else. Are there any warnings or error messages shown?

If not, jump over to the Network tab and find an entry called ws (you may need to reload the page for network entries to show up.

In a healthy situation there should only be one ws entry, and it should be in a Pending state. If you click on the entry and look in Messages, you should see something like what's shown below.

Screen Shot 2021-02-23 at 15 07 33
domesticwarlord86 commented 3 years ago

So there were quite a bit of errors.

Screenshot 2021-02-23 090916

Then I went to the netowkr tab and ws like you suggested, hit reload to get the stuff to show up... and reloading made it work lol. I feel like such a newb.

LukeChannings commented 3 years ago

@domesticwarlord86

Haha, classic!

As long as you can't reproduce it we'll call it a win. If the problem returns just comment and I'll re-open.

Thanks for your help debugging this!