CyferShepard / Jellystat

Jellystat is a free and open source Statistics App for Jellyfin
MIT License
1.08k stars 32 forks source link

Make the app compatible with reverse proxies #80

Open libussa opened 1 year ago

libussa commented 1 year ago

Hello! Nice job on this app :) Currently, the docker compose setup is incompatible with having a reverse proxy in front, due to the websocket port being used (and different than the main app) When using a reverse proxy, the frontend tries to hit the websocket port which is not exposed: docker-jellystat-1 | [1] [HPM] Error occurred while proxying request jellystat.domain.com/api/getconfig to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

CyferShepard commented 1 year ago

hey @libussa , so the websocket currently does not work but in the unstable build it has been fixed so that you only need port 3000 exposed. also which reverse proxy are you using and whats your setup? im using Nginx Proxy manager and it has been working great for me.

libussa commented 1 year ago

Ok, I switched to unstable but it still fails :/ The error: docker-jellystat-1 | [1] [HPM] Error occurred while proxying request jellystat.domain.com/socket.io/?EIO=4&transport=polling&t=OguPNOZ to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

I'm using trafik, telling it to target port 3000 on the container

CyferShepard commented 1 year ago

hey @libussa , sorry for the delay was abit busy, il try to replicate this on my side and see what could be the issue. i know a few others use trafik as well so maybe its a config issue

Jerrk commented 1 year ago

im not using reverse proxy but it looks like i'm getting the same error messages. i'm also getting a bunch of warnings when starting the container which may or may not be related.

unraid unstable branch

> jfstat@1.0.8 start-app
> concurrently "npm run start-server" "npm start"

[0] 
[0] > jfstat@1.0.8 start-server
[0] > cd backend && node server.js
[0] 
[1] 
[1] > jfstat@1.0.8 start
[1] > react-scripts start
[1] 
[0] Error: connect ECONNREFUSED 192.168.1.100:5432
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[0] FS-related option specified for migration configuration. This resets migrationSource to default FsMigrations
[0] FS-related option specified for migration configuration. This resets migrationSource to default FsMigrations
[0] node:internal/process/promises:289
[0]             triggerUncaughtException(err, true /* fromPromise */);
[0]             ^
[0] 
[0] Error: connect ECONNREFUSED 192.168.1.100:5432
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
[0]   errno: -111,
[0]   code: 'ECONNREFUSED',
[0]   syscall: 'connect',
[0]   address: '192.168.1.100',
[0]   port: 5432
[0] }
[0] 
[0] Node.js v20.8.1
[0] npm run start-server exited with code 1
[1] Browserslist: caniuse-lite is outdated. Please run:
[1]   npx update-browserslist-db@latest
[1]   Why you should do it regularly: https://github.com/browserslist/update-db#readme
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] [HPM] Proxy created: /  -> http://127.0.0.1:3003
[1] Proxy middleware applied
[1] (node:90) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[1] (Use `node --trace-deprecation ...` to show where the warning was created)
[1] (node:90) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[1] Starting the development server...
[1] 
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9FE4 to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] Compiled with warnings.
[1] 
[1] [eslint] 
[1] src/pages/components/sessions/sessions.js
[1]   Line 36:25:  Expected '===' and instead saw '=='  eqeqeq
[1] 
[1] Search for the keywords to learn more about each warning.
[1] To ignore, add // eslint-disable-next-line to the line before.
[1] 
[1] WARNING in [eslint] 
[1] src/pages/components/sessions/sessions.js
[1]   Line 36:25:  Expected '===' and instead saw '=='  eqeqeq
[1] 
[1] webpack compiled with 1 warning
[1] Compiling...
[1] Compiled with warnings.
[1] 
[1] [eslint] 
[1] src/pages/components/sessions/sessions.js
[1]   Line 36:25:  Expected '===' and instead saw '=='  eqeqeq
[1] 
[1] Search for the keywords to learn more about each warning.
[1] To ignore, add // eslint-disable-next-line to the line before.
[1] 
[1] WARNING in [eslint] 
[1] src/pages/components/sessions/sessions.js
[1]   Line 36:25:  Expected '===' and instead saw '=='  eqeqeq
[1] 
[1] webpack compiled with 1 warning
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9Yhh to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/auth/isConfigured to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/auth/isConfigured to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/api/getconfig to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/api/getconfig to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9YvK to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9ZH7 to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9aVT to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9bxC to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9dOx to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9esi to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9gKT to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9hoE to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] [HPM] Error occurred while proxying request 192.168.1.100:3003/socket.io/?EIO=4&transport=polling&t=OjK9jG6 to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
CyferShepard commented 1 year ago

hey @Jerrk , your error is not related to this, it looks like your backend failed to start, and when the internal proxy service tried to connect from the front end to the back it failed. the initial failure seems to be when it tries to connect to your postgres instance.

bubylou commented 1 year ago

I'm seeing the same error with traefik using kubernetes and the unstable version of jellystat. I also tried it with just docker and had the same issue. The docker error is posted below along with the example compose file I tried..

[1] [HPM] Error occurred while proxying request jellystat.localhost/api/getTaskSettings to http://127.0.0.1:3003/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

version: '3'
services:
  jellystat-db:
    image: postgres:15.2
    environment:
      POSTGRES_DB: 'jfstat'
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mypassword
    volumes:
    - ./postgres-data:/var/lib/postgresql/data # Mounting the volume
  jellystat:
    image: cyfershepard/jellystat:unstable
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mypassword
      POSTGRES_IP: jellystat-db
      POSTGRES_PORT: 5432
      JWT_SECRET: 'my-secret-jwt-key'
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.jellystat.rule=Host(`jellystat.localhost`)"
      - "traefik.http.routers.jellystat.entrypoints=web"
    ports:
      - "3000:3000" #Server Port
    volumes:
      - ./backup-data:/app/backend/backup-data # Mounting the volume

    depends_on:
      - jellystat-db
  traefik:
    image: "traefik:v2.10"
    container_name: "traefik"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
  default:
MrC-85 commented 1 year ago

I have Jellystat working with Traefik, this is my config:

`
jellystat-db: image: postgres environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: **** volumes:

bubylou commented 12 months ago

Seems to be working fine now in Docker. I get the same issue in Kubernetes though but I can try figuring that out myself. @MrC-85 you have to use 3 backticks before and after the code snippet to get it formatted correctly.

Kappawaii commented 8 months ago

This seems to be still broken :( I tried main as well as unstable and both bring me the same error on loop. I can't get the internal URL towards jellyfin to work so I typed in my full URL behind NginxProxyManager and that passed the setup page, then I get this error on loop :

[JELLYFIN-API] {
  ErrorAt: 'at AxiosError.from (/app/node_modules/axios/dist/node/axios.cjs:837:14',
  Message: 'connect ECONNREFUSED 127.0.0.1:80'
}

I'm on unraid and using the community package but I've tried using docker compose and that also doesn't work :(

Here's my docker-compose :

version: '3'
services:
  jellystat-db:
    image: postgres:15.2
    environment:
      POSTGRES_DB: 'jfstat'
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mypassword
    volumes:
    - ./postgres-data:/mnt/user/appdata/postgresql15 # Mounting the volume
  jellystat:
    image: cyfershepard/jellystat:unstable
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mypassword
      POSTGRES_IP: jellystat-db
      POSTGRES_PORT: 5432
      JWT_SECRET: 'my-secret-jwt-key'
    ports:
      - "3000:3000" #Server Port
    volumes:
      - ./backup-data:/mnt/user/Backups/Jellystat-backup # Mounting the volume

networks:
  default:
CyferShepard commented 8 months ago

Hey @Kappawaii , the error your experiencing is something else related to #163 . Jellystat does work behind a reverse proxy eg jellystat.domain.local but it currently doesn't support a baseurl so domain.local/jellystat doesnt work yet

RynoXLI commented 8 months ago

I stumbled upon a similar issue:

https://stackoverflow.com/a/69796397/10141502

I fixed this issue by going into backend/server.js and editing this:

server.listen(PORT, async () => {
        console.log(
          `[JELLYSTAT] Server listening on http://${LISTEN_IP}:${PORT}`
        );
        ActivityMonitor.ActivityMonitor(1000);
        tasks.FullSyncTask();
        tasks.RecentlyAddedItemsSyncTask();
        tasks.BackupTask();
      });

To this:

server.listen(PORT, '0.0.0.0', async () => {
        console.log(
          `[JELLYSTAT] Server listening on http://${LISTEN_IP}:${PORT}`
        );
        ActivityMonitor.ActivityMonitor(1000);
        tasks.FullSyncTask();
        tasks.RecentlyAddedItemsSyncTask();
        tasks.BackupTask();
      });

Rebuilt the docker image: docker build . -t jellystat Then updated the image name in jellystat and it now works::

My docker-compse for reference.

version: '3'
services:
  jellystat-db:
    container_name: jellystat-db
    image: postgres:15.2
    environment:
      POSTGRES_DB: 'jfstat'
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: $JELLYSTAT_POSTGRES_PASSWORD
    networks:
      - proxy
    volumes:
      - $DATA_LOCATION/postgres-jellystat/data/:/var/lib/postgresql/data # Mounting the volume
  jellystat:
    container_name: jellystat
    image: jellystat:latest
    ports:
      - 3000:3000
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: $JELLYSTAT_POSTGRES_PASSWORD
      POSTGRES_IP: jellystat-db
      POSTGRES_PORT: 5432
      JWT_SECRET: $JELLYSTAT_JWT_SECRET
      TZ: $TZ
    depends_on:
      - jellystat-db
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.jellystat.entrypoints=https" # could be websecure for you
      - "traefik.http.routers.jellystat.rule=Host(`jellystat.$DOMAIN`)"
      - "traefik.http.services.jellystat.loadbalancer.server.port=3000"
      - traefik.http.routers.jellystat.service=jellystat
      - "traefik.docker.network=$NETWORK"
    volumes:
      - $DATA_LOCATION/jellystat/backup:/app/backend/backup-data # Mounting the volume
    networks:
      - proxy

networks:
  proxy:
    external: true
    name: $NETWORK

Most likely a quick PR to fix this.