diff --git a/README.md b/README.md index 5ba89c0..6127343 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,29 @@ ng generate --help ## Building +### Local (com Node instalado) + To build the project run: ```bash -ng build +npm run build ``` -This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed. +### VPS/Servidor sem Node no host (recomendado neste projeto) + +Execute o build **dentro do container Docker do frontend**: + +```bash +docker compose -f docker-compose.frontend.yml run --rm frontend-builder +``` + +Se quiser rodar exatamente o comando `npm run build` dentro do container: + +```bash +docker compose -f docker-compose.frontend.yml run --rm frontend-builder sh -lc "npm run build" +``` + +Os artefatos serão gerados em `dist/line-gestao-frontend`. ## Running unit tests diff --git a/docker/nginx.frontend.conf b/docker/nginx.frontend.conf index 79fd959..67620cd 100644 --- a/docker/nginx.frontend.conf +++ b/docker/nginx.frontend.conf @@ -3,9 +3,14 @@ server { server_name _; root /usr/share/nginx/html; - index index.html; + index index.csr.html; + + # Angular SSR static browser build uses index.csr.html as the SPA entrypoint. + location = /index.html { + try_files /index.csr.html =404; + } location / { - try_files $uri $uri/ /index.html; + try_files $uri $uri/ /index.csr.html; } } diff --git a/docs/DEPLOY_VPS.md b/docs/DEPLOY_VPS.md index 7c8e8d5..d03d03c 100644 --- a/docs/DEPLOY_VPS.md +++ b/docs/DEPLOY_VPS.md @@ -43,13 +43,16 @@ cd ~/apps/line-gestao-frontend cat > src/environments/environment.production.ts <<'EOT' export const environment = { production: true, - apiUrl: 'https://linegestao.inglinesystems.com.br' + apiUrl: '' }; EOT -# 3) build de produção via container Node +# 3) build de produção via container Node (não rodar npm no host) docker compose -f docker-compose.frontend.yml run --rm frontend-builder +# opcional: equivalente a executar `npm run build` dentro do container +# docker compose -f docker-compose.frontend.yml run --rm frontend-builder sh -lc "npm run build" + # 4) validar saída estática ls -lah dist/line-gestao-frontend/browser ``` @@ -85,6 +88,25 @@ cd ~/apps/line-gestao-api docker compose -f docker-compose.domain.yml up -d caddy ``` + +## 404 no domínio após build (caso comum neste projeto) + +Se o container `frontend-nginx` subir, mas `https://linegestao.inglinesystems.com.br` continuar em 404, valide: + +```bash +# 1) arquivo de entrada do build Angular SSR +ls -lah ~/apps/line-gestao-frontend/dist/line-gestao-frontend/browser/index.csr.html + +# 2) recarregar Nginx do front após atualizar config +cd ~/apps/line-gestao-frontend +docker compose -f docker-compose.frontend.yml up -d --force-recreate frontend-nginx + +# 3) testar origem do Nginx localmente no VPS +curl -i http://127.0.0.1:8081/ +``` + +Neste repositório, o Nginx do front deve apontar para `index.csr.html` (e não `index.html`). + --- ## Bloco C — validação (curl + navegador) diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 179c3c2..e76a9fe 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -1,4 +1,4 @@ export const environment = { production: true, - apiUrl: 'https://linegestao.inglinesystems.com.br' + apiUrl: '' };