zoriya / Kyoo

A portable and vast media library solution.
https://kyoo.zoriya.dev
GNU General Public License v3.0
1.64k stars 38 forks source link

Redirect Loop during Setup #525

Closed mircogericke closed 2 months ago

mircogericke commented 3 months ago

Kyoo's version

4.6

What happened?

After the initial docker compose up -d opening http://localhost:8901/ automatically redirects to the setup page at http://localhost:8901/setup?step=MissingAdminAccount, which contains only a register button.

Pressing that register button redirects to http://localhost:8901/register, which automatically redirects back to http://localhost:8901/setup?step=MissingAdminAccount after loading causing you to get stuck in a loop.

I used the default docker compose file and .env file linked in the v4.6 install instructions, only changed KYOO_APIKEYS. Disabling all OIDC providers does not change the behavior.

I'm pretty sure it's caused by RegisterPage.getFetchUrls containing a call to the GetServerInfo endpoint, although I didn't find the time to figure out how this actually ends up getting called.

zoriya commented 3 months ago

That's weird, I can't reproduce this on my end. The register page is explicitly whitelisted from the redirect behavior of the SetupPage.

I tested this using a fresh copy of the docker-compose/.env files.

Thanks for taking the time to try to debug this, getFetchUrls is called in the _app.tsx's getInitialProps to load data during SSR. This should not be the cause of the issue, the culprit is more likely to be the SetupChecker component defined in _app.tsx (here).

Are you perhaps running Kyoo under a subpath (as in https://example.com/kyoo)? Since SetupChecker is explicitly checking for a route named /register this might be the cause.

breakingflower commented 3 months ago

I have a similar issue. Fresh install, 4.6 / edge tested in docker. Frontend is reachable locally, can't get it to work with traefik proxy. upon disabling oidc and attempting to register an admin user, get the following:

front-1  |  ⨯ TypeError: Cannot set properties of undefined (setting '__lang')
front-1  |     at a.getInitialProps (/app/.next/server/chunks/807.js:1:702)
front-1  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
front-1  |     at async X (/app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5045)
front-1  |     at async e3 (/app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:25:3773)
front-1  |     at async doRender (/app/node_modules/next/dist/server/base-server.js:1425:30)
front-1  |     at async cacheEntry.responseCache.get.routeKind (/app/node_modules/next/dist/server/base-server.js:1599:28)
front-1  |     at async NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/dist/server/base-server.js:1507:28)
front-1  |     at async NextNodeServer.renderErrorToResponseImpl (/app/node_modules/next/dist/server/base-server.js:2182:24)
front-1  |     at async pipe.req.req (/app/node_modules/next/dist/server/base-server.js:2056:30)
front-1  |     at async NextNodeServer.pipeImpl (/app/node_modules/next/dist/server/base-server.js:920:25)

image

I also don't understand why the backend service needs to be proxied with traefik. I cant seem to set it up correctly, used the following for the frontend:

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.kyoo.rule=Host(`kyoo.myhost`)"
      - "traefik.http.routers.kyoo.entrypoints=myentrypoint"
      - "traefik.http.routers.kyoo.tls.certresolver=mytlsresolver"
      - "traefik.http.services.kyoo.loadbalancer.server.port=8901"

Result is a Bad Gateway

Any help is appreciated.

zoriya commented 2 months ago

You should not change the traefik config, the frontend expects the api to be reachable from /api.

I see where the traceback from the front is from, I'll try to reproduce it locally (but the main issue is the traefik config)

breakingflower commented 2 months ago

@zoriya , thanks. im curious to hear the rationale why you want the backend api service to be exposed to the internet. Usually you see the opposite: only frontend is exposed, rest is internal networking, e.g. backend:5000/api like you do with the transcoder config. Can you share some insight?

Will re-test with api exposed if the traceback for front is fixed.

zoriya commented 2 months ago

The backend is exposed because the front makes requests to it to get data. We use hydratation (so only the first requests is rendered on the server, future requests are made directly in the browser). The API is also used by the android client.

The traceback front should not happen if the back is up. It's because I forgot to handle the "back unreachable" case in this part of the code.

breakingflower commented 2 months ago

Hi

My compose file looks like the following, with external traefik proxy ( i already have one running):

  back:
    image: ghcr.io/zoriya/kyoo_back:4.6
    restart: unless-stopped
    cpus: 8
    environment:
      - TRANSCODER_URL=${TRANSCODER_URL:-http://transcoder:7666}
    env_file:
      - ./.env
    depends_on:
      postgres:
        condition: service_healthy
      meilisearch:
        condition: service_healthy
      rabbitmq:
        condition: service_healthy
      migrations:
        condition: service_completed_successfully
    volumes:
      - kyoo:/metadata
    networks:
      - default
      - proxy
    labels:
      - "traefik.enable=true"
      # - "traefik.http.routers.kyoo-api.rule=PathPrefix(`/api/`)"
      - "traefik.http.routers.kyoo-api.rule=Host(`abc`) && PathPrefix(`/api/`)"
      - "traefik.http.routers.kyoo-api.middlewares=kyoo-api-sp"
      - "traefik.http.routers.kyoo-api.entrypoints=myentrypoint"
      - "traefik.http.middlewares.kyoo-api-sp.stripprefix.prefixes=/api"
      # - "traefik.http.middlewares.kyoo-api-sp.stripprefix.forceSlash=false"

  front:
    image: ghcr.io/zoriya/kyoo_front:4.6
    restart: unless-stopped
    networks:
      - default
      - proxy
    ports:
      - 8901:8901
    environment:
      - KYOO_URL=${KYOO_URL:-http://back:5000}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.kyoo.rule=Host(`abc`) && PathPrefix(`/`)"
      - "traefik.http.routers.kyoo.entrypoints=myentrypoint"
      - "traefik.http.routers.kyoo.tls.certresolver=mytlsresolver"
      - "traefik.http.services.kyoo.loadbalancer.server.port=8901"

Traefik logs give me the following, so i commented out the forceslash:

2024-07-05T07:16:06+02:00 WRN `ForceSlash` option is deprecated, please remove any usage of this option. .... middlewareName=kyoo-api-sp@docker middlewareType=StripPrefix routerName=kyoo-api@docker

This setup works for all my http services / routes.

I'm getting a bad gateway on the proxied frontend. I am able to connect locally using the port, but I cant register (same err as before).

I dont fully understand what you mean with the sentence The backend is exposed because the front makes requests to it to get data. Can you please elaborate what you mean?