Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
Fix/e2e api base (#1)
Carter9294c8fdb61d
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.ymlindex c4fc732..851533c 100644--- a/.github/workflows/docker.yml+++ b/.github/workflows/docker.yml@@ -2,7 +2,7 @@ name: Build & Push to Docker Hubon:push:- branches: [main]+ branches: ['**']tags: ['v*']pull_request:branches: [main]@@ -20,7 +20,6 @@ jobs:- run: cd backend && go test ./controllers/ -timeout 30se2e:- if: false # disabled — fix in progress on fix/e2e-api-base branchruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4@@ -30,8 +29,19 @@ jobs:echo "JWT_SECRET=ci-test-secret-$(openssl rand -hex 16)" >> .envecho "PORT=80" >> .env- - name: Build and start stack- run: docker compose up -d --build --wait+ - uses: docker/setup-buildx-action@v3++ - name: Build images with layer cache+ run: |+ docker buildx bake \+ --set "backend.cache-from=type=gha,scope=lyftr-backend" \+ --set "backend.cache-to=type=gha,scope=lyftr-backend,mode=max" \+ --set "frontend.cache-from=type=gha,scope=lyftr-frontend" \+ --set "frontend.cache-to=type=gha,scope=lyftr-frontend,mode=max" \+ --load++ - name: Start stack+ run: docker compose up -d --wait- uses: actions/setup-node@v4with:@@ -41,7 +51,19 @@ jobs:- run: cd web && npm ci- - run: cd web && npx playwright install chromium --with-deps+ - name: Cache Playwright browsers+ uses: actions/cache@v4+ id: playwright-cache+ with:+ path: ~/.cache/ms-playwright+ key: playwright-${{ runner.os }}-${{ hashFiles('web/package-lock.json') }}++ - name: Install Playwright browsers+ if: steps.playwright-cache.outputs.cache-hit != 'true'+ run: cd web && npx playwright install chromium webkit++ - name: Install Playwright system dependencies+ run: cd web && npx playwright install-deps chromium webkit- name: Wait for demo user to be seededrun: |@@ -61,14 +83,14 @@ jobs:retention-days: 7build-backend:- needs: [test]+ needs: [test, e2e]runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: docker/setup-qemu-action@v3- uses: docker/setup-buildx-action@v3- uses: docker/login-action@v3- if: github.event_name != 'pull_request'+ if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')with:username: ${{ secrets.DOCKERHUB_USERNAME }}password: ${{ secrets.DOCKERHUB_TOKEN }}@@ -83,20 +105,20 @@ jobs:with:context: ./backendplatforms: linux/amd64,linux/arm64,linux/arm/v7- push: ${{ github.event_name != 'pull_request' }}+ push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}tags: ${{ steps.meta.outputs.tags }}- cache-from: type=gha- cache-to: type=gha,mode=max+ cache-from: type=gha,scope=lyftr-backend+ cache-to: type=gha,scope=lyftr-backend,mode=maxbuild-frontend:- needs: [test]+ needs: [test, e2e]runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: docker/setup-qemu-action@v3- uses: docker/setup-buildx-action@v3- uses: docker/login-action@v3- if: github.event_name != 'pull_request'+ if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')with:username: ${{ secrets.DOCKERHUB_USERNAME }}password: ${{ secrets.DOCKERHUB_TOKEN }}@@ -111,7 +133,7 @@ jobs:with:context: ./webplatforms: linux/amd64,linux/arm64,linux/arm/v7- push: ${{ github.event_name != 'pull_request' }}+ push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}tags: ${{ steps.meta.outputs.tags }}- cache-from: type=gha- cache-to: type=gha,mode=max+ cache-from: type=gha,scope=lyftr-frontend+ cache-to: type=gha,scope=lyftr-frontend,mode=maxdiff --git a/web/e2e/config.ts b/web/e2e/config.tsindex 2b8c015..004e009 100644--- a/web/e2e/config.ts+++ b/web/e2e/config.ts@@ -1,15 +1,26 @@-// Configure E2E tests for self-hosted instances by setting env vars.-// Both Vite (dev) and nginx (prod) proxy /api through the frontend host,-// so BASE_URL is the only var you normally need to change.-//-// Dev: BASE_URL defaults to http://localhost:5173 (Vite proxy → :3000)-// Docker: BASE_URL=http://localhost (nginx proxy → backend:3000)-// Custom: BASE_URL=https://lyftr.example.com-//-// Override just the API separately only if it's on a different host:-// API_URL=https://api.example.com/api/v1+import { readFileSync } from 'fs'+import { resolve } from 'path'+import { fileURLToPath } from 'url'+import path from 'path'-const base = (process.env.BASE_URL ?? 'http://localhost:5173').replace(/\/$/, '')+const __dirname = path.dirname(fileURLToPath(import.meta.url))++function getBase(): string {+ if (process.env.BASE_URL) return process.env.BASE_URL.replace(/\/$/, '')+ if (process.env.E2E_DOCKER) {+ try {+ const env = readFileSync(resolve(__dirname, '../../.env'), 'utf8')+ const match = env.match(/^PORT=(\d+)/m)+ const port = match?.[1] ?? '80'+ return port === '80' ? 'http://localhost' : `http://localhost:${port}`+ } catch {+ return 'http://localhost'+ }+ }+ return 'http://localhost:5173'+}++const base = getBase()export const API_BASE = process.env.API_URL ?? `${base}/api/v1`export const TEST_EMAIL = process.env.TEST_EMAIL ?? '[email protected]'diff --git a/web/e2e/workouts.spec.ts b/web/e2e/workouts.spec.tsindex 4b42b05..ca6a7ea 100644--- a/web/e2e/workouts.spec.ts+++ b/web/e2e/workouts.spec.ts@@ -88,6 +88,7 @@ test.describe('Workouts', () => {})test('delete workout shows confirm dialog', async ({ page }) => {+ await expect(page.getByText(SEED_WORKOUT_NAME)).toBeVisible({ timeout: 5000 })// On mobile the delete button is behind a kebab (⋯) menu — open it first if presentconst optionsBtn = page.getByRole('button', { name: /options/i }).first()if (await optionsBtn.isVisible()) {diff --git a/web/src/services/api.ts b/web/src/services/api.tsindex 8e7a346..dfa48f7 100644--- a/web/src/services/api.ts+++ b/web/src/services/api.ts@@ -2,8 +2,8 @@ import axios, { AxiosInstance } from 'axios'import * as types from '../types'const getAPIBase = () => {- const serverUrl = localStorage.getItem('server_url') || 'http://localhost:3000'- return `${serverUrl}/api/v1`+ const serverUrl = localStorage.getItem('server_url')+ return serverUrl ? `${serverUrl}/api/v1` : '/api/v1'}const API_BASE = (import.meta.env.VITE_API_URL as string) || getAPIBase()