Ambiente e Configuração
Variáveis de Ambiente
Seção intitulada “Variáveis de Ambiente”Toda a configuração é feita através de variáveis de ambiente no seu arquivo .env na raiz do projeto.
Importante: Rebase utiliza Zod para validar variáveis de ambiente na inicialização em
src/env.ts. Se alguma variável obrigatória estiver faltando ou formatada incorretamente (como URLs ou portas), o servidor não conseguirá iniciar e fornecerá uma mensagem de erro clara.
Obrigatórias
Seção intitulada “Obrigatórias”| Variável | Descrição | Exemplo |
|---|---|---|
DATABASE_URL | String de conexão PostgreSQL | postgresql://user:pass@localhost:5432/mydb |
JWT_SECRET | Chave secreta para assinar tokens JWT. Use uma string aleatória forte (mínimo 32 caracteres). | a1b2c3d4e5... |
Frontend
Seção intitulada “Frontend”| Variável | Descrição | Padrão |
|---|---|---|
VITE_API_URL | URL da API de backend. Usada pelo SDK do cliente. | http://localhost:3001 |
VITE_GOOGLE_CLIENT_ID | ID do cliente Google OAuth. Habilita “Fazer login com o Google”. | — |
Backend
Seção intitulada “Backend”| Variável | Descrição | Padrão |
|---|---|---|
PORT | Porta para o servidor HTTP de backend | 3001 |
LOG_LEVEL | Nível de verbosidade de log: error, warn, info, debug | info |
NODE_ENV | Ambiente: development ou production | development |
Autenticação
Seção intitulada “Autenticação”| Variável | Descrição | Padrão |
|---|---|---|
JWT_SECRET | Segredo para assinatura JWT (obrigatório se a autenticação estiver habilitada) | — |
JWT_ACCESS_EXPIRES_IN | Tempo de vida do token de acesso | 1h |
JWT_REFRESH_EXPIRES_IN | Tempo de vida do token de atualização | 30d |
ALLOW_REGISTRATION | Permitir que novos usuários se registrem (true/false). O primeiro usuário sempre pode se registrar. | true |
GOOGLE_CLIENT_ID | ID do cliente Google OAuth (validação de backend) | — |
Armazenamento
Seção intitulada “Armazenamento”| Variável | Descrição | Padrão |
|---|---|---|
STORAGE_TYPE | Backend de armazenamento: local ou s3 | local |
STORAGE_PATH | Caminho base para armazenamento local | ./uploads |
S3_BUCKET | Nome do bucket S3 (quando STORAGE_TYPE=s3) | — |
S3_REGION | Região AWS | — |
S3_ACCESS_KEY_ID | Chave de acesso AWS | — |
S3_SECRET_ACCESS_KEY | Chave secreta AWS | — |
S3_ENDPOINT | Endpoint S3 personalizado (para MinIO, Cloudflare R2, etc.) | — |
Email (Opcional)
Seção intitulada “Email (Opcional)”| Variável | Descrição |
|---|---|
SMTP_HOST | Host do servidor SMTP |
SMTP_PORT | Porta do servidor SMTP |
SMTP_SECURE | Enable secure connection (true/false) |
SMTP_USER | Nome de usuário SMTP |
SMTP_PASS | Senha SMTP |
EMAIL_FROM | Endereço do remetente para e-mails do sistema |
Objeto de Configuração do Backend
Seção intitulada “Objeto de Configuração do Backend”O RebaseBackendConfig passado para initializeRebaseBackend() fornece controle programático:
import { initializeRebaseBackend } from "@rebasepro/server-core";import { createPostgresAdapter } from "@rebasepro/server-postgresql";import { env } from "./env";
await initializeRebaseBackend({ app, server, collectionsDir: "./config/collections", basePath: "/api", // Base path for all API routes (default: "/api")
database: createPostgresAdapter({ connection: db, schema: { tables, enums, relations } }),
auth: { // Authentication config jwtSecret: env.JWT_SECRET, accessExpiresIn: env.JWT_ACCESS_EXPIRES_IN, refreshExpiresIn: env.JWT_REFRESH_EXPIRES_IN, requireAuth: true, // Require auth for data API (default: true) allowRegistration: env.ALLOW_REGISTRATION, google: env.GOOGLE_CLIENT_ID ? { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET } : undefined, serviceKey: env.REBASE_SERVICE_KEY },
storage: env.STORAGE_TYPE === "s3" ? { type: "s3", bucket: env.S3_BUCKET!, region: env.S3_REGION, accessKeyId: env.S3_ACCESS_KEY_ID, secretAccessKey: env.S3_SECRET_ACCESS_KEY, endpoint: env.S3_ENDPOINT } : { type: "local", basePath: env.STORAGE_PATH || "./uploads" },
history: true, // Enable entity change history
enableSwagger: true, // Enable OpenAPI docs at /api/data/docs
logging: { level: "info" }});Próximos Passos
Seção intitulada “Próximos Passos”- Implantação — Guia de implantação em produção
- Visão Geral do Backend — Referência completa de configuração do backend