Salta ai contenuti

Ambiente e Configurazione

Tutta la configurazione viene gestita tramite variabili d’ambiente nel tuo file .env alla radice del progetto.

Importante: Rebase utilizza Zod per convalidare le variabili d’ambiente all’avvio in src/env.ts. Se mancano variabili richieste o sono formattate in modo errato (come URL o porte), il server non si avvierà e fornirà un messaggio di errore chiaro.

VariabileDescrizioneEsempio
DATABASE_URLStringa di connessione PostgreSQLpostgresql://user:pass@localhost:5432/mydb
JWT_SECRETChiave segreta per la firma dei token JWT. Utilizzare una stringa casuale forte (min 32 caratteri).a1b2c3d4e5...
VariabileDescrizionePredefinito
VITE_API_URLURL API del backend. Utilizzato dall’SDK client.http://localhost:3001
VITE_GOOGLE_CLIENT_IDID client Google OAuth. Abilita “Accedi con Google”.
VariabileDescrizionePredefinito
PORTPorta per il server HTTP del backend3001
LOG_LEVELVerbosità del logging: error, warn, info, debuginfo
NODE_ENVAmbiente: development o productiondevelopment
VariabileDescrizionePredefinito
JWT_SECRETSegreto per la firma JWT (richiesto se l’autenticazione è abilitata)
JWT_ACCESS_EXPIRES_INDurata del token di accesso1h
JWT_REFRESH_EXPIRES_INDurata del token di refresh30d
ALLOW_REGISTRATIONConsente ai nuovi utenti di registrarsi (true/false). Il primo utente può sempre registrarsi.true
GOOGLE_CLIENT_IDID client Google OAuth (validazione backend)
VariabileDescrizionePredefinito
STORAGE_TYPEBackend di archiviazione: local o s3local
STORAGE_PATHPercorso base per l’archiviazione locale./uploads
S3_BUCKETNome del bucket S3 (quando STORAGE_TYPE=s3)
S3_REGIONRegione AWS
S3_ACCESS_KEY_IDChiave di accesso AWS
S3_SECRET_ACCESS_KEYChiave segreta AWS
S3_ENDPOINTEndpoint S3 personalizzato (per MinIO, Cloudflare R2, ecc.)
VariabileDescrizione
SMTP_HOSTHost del server SMTP
SMTP_PORTPorta del server SMTP
SMTP_SECUREEnable secure connection (true/false)
SMTP_USERNome utente SMTP
SMTP_PASSPassword SMTP
EMAIL_FROMIndirizzo del mittente per le email di sistema

Il RebaseBackendConfig passato a initializeRebaseBackend() fornisce controllo programmatico:

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"
}
});