add prefix on frontend

This commit is contained in:
Gabriel Santana de Menezes 2026-05-13 21:03:14 -04:00
parent c6e9e6cc77
commit 38b6ddcd5d
8 changed files with 19 additions and 30 deletions

View file

@ -29,7 +29,7 @@ Backend (`cd backend`):
- Build: `./mvnw package` - Build: `./mvnw package`
Frontend (`cd frontend`): 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`) - Build: `npm run build` (runs `tsc -b` then `vite build`)
- Lint: `npm run lint` - 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**. - **React 19**, **Tailwind v4** (`@tailwindcss/vite`, no Tailwind config file required), **react-router-dom v7**.
- Folder layout: `pages/`, `components/`, `services/`, `contexts/`, `types/`, `lib/`. - 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/<feature>Service.ts` exporting an object of methods. - Each backend feature gets a service in `services/<feature>Service.ts` exporting an object of methods.
- Class merging uses `cn(...inputs)` from `src/lib/utils.ts` (clsx + tailwind-merge). - Class merging uses `cn(...inputs)` from `src/lib/utils.ts` (clsx + tailwind-merge).
- Icons: `lucide-react`. Animations: `framer-motion`. DnD: `@hello-pangea/dnd`. - Icons: `lucide-react`. Animations: `framer-motion`. DnD: `@hello-pangea/dnd`.

View file

@ -54,11 +54,13 @@ services:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.frontend.rule=PathPrefix(`/frontend`)" - "traefik.http.routers.frontend.rule=PathPrefix(`/frontend`)"
- "traefik.http.routers.frontend.entrypoints=websecure" - "traefik.http.routers.frontend.entrypoints=websecure"
- "traefik.http.routers.frontend.tls.certresolver=letsencrypt" - "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: volumes:
postgres_data: postgres_data:

6
frontend/Caddyfile Normal file
View file

@ -0,0 +1,6 @@
:80 {
root * /srv
encode gzip
try_files {path} /index.html
file_server
}

View file

@ -7,14 +7,14 @@ RUN npm ci
COPY . . COPY . .
ARG VITE_API_URL=/api ARG VITE_API_URL
ENV VITE_API_URL=$VITE_API_URL ENV VITE_API_URL=$VITE_API_URL
RUN npm run build RUN npm run build
FROM nginx:1.29-alpine FROM caddy:2-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY Caddyfile /etc/caddy/Caddyfile
COPY --from=build /app/dist /usr/share/nginx/html COPY --from=build /app/dist /srv
EXPOSE 80 EXPOSE 80

View file

@ -1,11 +0,0 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}

View file

@ -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) { function buildUrl(path: string) {
return `${API_BASE_URL}${path}` return `${API_BASE_URL}${path}`

View file

@ -91,4 +91,4 @@ export const router = createBrowserRouter([
}, },
], ],
}, },
]); ], { basename: '/frontend' });

View file

@ -4,17 +4,9 @@ import { defineConfig } from 'vite'
import pkg from './package.json' import pkg from './package.json'
export default defineConfig({ export default defineConfig({
base: '/frontend/',
define: { define: {
'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version), 'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version),
}, },
plugins: [react(), tailwindcss()], plugins: [react(), tailwindcss()],
server: {
proxy: {
'/api': {
target: process.env.VITE_API_PROXY_TARGET ?? 'http://localhost:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
}) })