Skip to content

Conversation

@ebigunso
Copy link
Owner

@ebigunso ebigunso commented Aug 19, 2025

Root cause

  • The UI container’s Vite dev proxy was targeting http://localhost:8080. Inside Docker, localhost points to the UI container itself, not the API container. As a result, proxying /login failed with ECONNREFUSED and Vite returned a 500.

What changed

  • sleep-ui/vite.config.ts
    • Introduced an env-configurable proxy target:
      const target = process.env.PROXY_TARGET ?? 'http://localhost:8080';
    • All proxy entries now use target.
  • compose.yaml (ui service)
    • Set PROXY_TARGET so Vite proxies to the API container on the compose network:
      environment:
        - PROXY_TARGET=http://api:8080

Why this fixes it

  • In Docker Compose, the API is reachable via the service hostname http://api:8080. Pointing Vite’s proxy at that host avoids ECONNREFUSED and eliminates the 500 on /login.

Testing

  1. Ensure .env.docker contains valid values:
    • ADMIN_EMAIL
    • ADMIN_PASSWORD_HASH (argon2id string)
    • SESSION_SECRET (base64)
  2. Rebuild and start:
    docker compose up --build
  3. Open http://localhost:5173/login and sign in.
  4. Verify /api/session reflects authentication and protected routes (/sleep, etc.) work.

Local Docker cookie considerations

  • By default, the API sets Secure cookies (COOKIE_SECURE defaults to true). Over plain HTTP, browsers ignore Secure cookies, so sessions won’t persist.
  • For local dev without TLS, set this in .env.docker (dev-only):
    COOKIE_SECURE=0
    Or keep Secure cookies and terminate TLS in front of the stack (e.g., Traefik/Nginx).

Files changed

  • sleep-ui/vite.config.ts
  • compose.yaml

Commits

  • ui(vite): make proxy target configurable via PROXY_TARGET for Docker networking
  • compose(ui): set PROXY_TARGET to http://api:8080 so Vite proxies to API container; resolves ECONNREFUSED 500 on /login in Docker

Copilot AI review requested due to automatic review settings August 19, 2025 18:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a Docker networking issue where login requests from the UI container were failing with 500 errors because Vite was proxying to localhost instead of the API container.

  • Made Vite proxy target configurable via PROXY_TARGET environment variable
  • Updated Docker Compose to set PROXY_TARGET to point to the API container
  • Replaced hardcoded localhost:8080 targets with the configurable variable across all proxy routes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sleep-ui/vite.config.ts Introduces PROXY_TARGET environment variable and updates all proxy configurations to use it
compose.yaml Sets PROXY_TARGET=http://api:8080 for the UI service to enable proper Docker networking

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ebigunso ebigunso self-assigned this Aug 20, 2025
@ebigunso ebigunso changed the title Fix Docker login 500: point Vite proxy to API container via PROXY_TARGET 🐛 Fix Docker login 500: point Vite proxy to API container via PROXY_TARGET Aug 20, 2025
@ebigunso ebigunso merged commit 3b7ea78 into main Aug 20, 2025
2 checks passed
@ebigunso ebigunso deleted the feature/2025-08-20/fix-login-error-in-docker branch August 20, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants