From 38b6ddcd5d831782fb951d12d5dae61dc5a02134 Mon Sep 17 00:00:00 2001 From: Gabriel Santana de Menezes Date: Wed, 13 May 2026 21:03:14 -0400 Subject: [PATCH] add prefix on frontend --- CLAUDE.md | 4 ++-- deploy/docker-compose.prod.yml | 6 ++++-- frontend/Caddyfile | 6 ++++++ frontend/Dockerfile | 8 ++++---- frontend/nginx.conf | 11 ----------- frontend/src/lib/api.ts | 2 +- frontend/src/router.tsx | 2 +- frontend/vite.config.ts | 10 +--------- 8 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 frontend/Caddyfile delete mode 100644 frontend/nginx.conf diff --git a/CLAUDE.md b/CLAUDE.md index feaf863..62c4899 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -29,7 +29,7 @@ Backend (`cd backend`): - Build: `./mvnw package` Frontend (`cd frontend`): -- Dev: `npm run dev` (port 5173, proxies `/api/*` → `http://localhost:8080`) +- Dev: `npm run dev` (port 5173, calls backend directly at `http://localhost:8080` via `VITE_API_URL`) - Build: `npm run build` (runs `tsc -b` then `vite build`) - Lint: `npm run lint` @@ -90,7 +90,7 @@ The authenticated email comes from `securityIdentity.getPrincipal().getName()` a - **React 19**, **Tailwind v4** (`@tailwindcss/vite`, no Tailwind config file required), **react-router-dom v7**. - Folder layout: `pages/`, `components/`, `services/`, `contexts/`, `types/`, `lib/`. -- HTTP through `apiFetch` in `src/lib/api.ts` — it auto-injects the JWT from `localStorage.user.jwt` and prefixes `VITE_API_URL` (defaults to `/api`, proxied by Vite to the backend). +- HTTP through `apiFetch` in `src/lib/api.ts` — it auto-injects the JWT from `localStorage.user.jwt` and prefixes `VITE_API_URL` (defaults to `http://localhost:8080` em dev; configurar para a URL real do backend em prod). - Each backend feature gets a service in `services/Service.ts` exporting an object of methods. - Class merging uses `cn(...inputs)` from `src/lib/utils.ts` (clsx + tailwind-merge). - Icons: `lucide-react`. Animations: `framer-motion`. DnD: `@hello-pangea/dnd`. diff --git a/deploy/docker-compose.prod.yml b/deploy/docker-compose.prod.yml index 537715f..4276b7b 100644 --- a/deploy/docker-compose.prod.yml +++ b/deploy/docker-compose.prod.yml @@ -54,11 +54,13 @@ services: - "traefik.enable=true" - "traefik.http.routers.frontend.rule=PathPrefix(`/frontend`)" - - "traefik.http.routers.frontend.entrypoints=websecure" - "traefik.http.routers.frontend.tls.certresolver=letsencrypt" + - "traefik.http.routers.frontend.middlewares=frontend-strip" - - "traefik.http.services.frontend.loadbalancer.server.port=3000" + - "traefik.http.middlewares.frontend-strip.stripprefix.prefixes=/frontend" + + - "traefik.http.services.frontend.loadbalancer.server.port=80" volumes: postgres_data: diff --git a/frontend/Caddyfile b/frontend/Caddyfile new file mode 100644 index 0000000..a709d7f --- /dev/null +++ b/frontend/Caddyfile @@ -0,0 +1,6 @@ +:80 { + root * /srv + encode gzip + try_files {path} /index.html + file_server +} diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 23f6004..9b4fb93 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -7,14 +7,14 @@ RUN npm ci COPY . . -ARG VITE_API_URL=/api +ARG VITE_API_URL ENV VITE_API_URL=$VITE_API_URL RUN npm run build -FROM nginx:1.29-alpine +FROM caddy:2-alpine -COPY nginx.conf /etc/nginx/conf.d/default.conf -COPY --from=build /app/dist /usr/share/nginx/html +COPY Caddyfile /etc/caddy/Caddyfile +COPY --from=build /app/dist /srv EXPOSE 80 diff --git a/frontend/nginx.conf b/frontend/nginx.conf deleted file mode 100644 index 79fd959..0000000 --- a/frontend/nginx.conf +++ /dev/null @@ -1,11 +0,0 @@ -server { - listen 80; - server_name _; - - root /usr/share/nginx/html; - index index.html; - - location / { - try_files $uri $uri/ /index.html; - } -} diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 183ed9c..3648c2c 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,4 +1,4 @@ -const API_BASE_URL = (import.meta.env.VITE_API_URL as string | undefined) ?? '/api' +const API_BASE_URL = (import.meta.env.VITE_API_URL as string | undefined) ?? 'http://localhost:8080' function buildUrl(path: string) { return `${API_BASE_URL}${path}` diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx index 2abd3d7..0b0ebaa 100644 --- a/frontend/src/router.tsx +++ b/frontend/src/router.tsx @@ -91,4 +91,4 @@ export const router = createBrowserRouter([ }, ], }, -]); +], { basename: '/frontend' }); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index cc44d1b..0150f05 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,17 +4,9 @@ import { defineConfig } from 'vite' import pkg from './package.json' export default defineConfig({ + base: '/frontend/', define: { 'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version), }, plugins: [react(), tailwindcss()], - server: { - proxy: { - '/api': { - target: process.env.VITE_API_PROXY_TARGET ?? 'http://localhost:8080', - changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, ''), - }, - }, - }, })