This guide explains how to configure different environments (development and production) for both frontend and backend.
Create the following files in the frontend/ directory:
.env.development# Development Environment Variables
VITE_API_BASE_URL=http://localhost:8091/api/v1
VITE_APP_NAME=PlotPulse (Dev)
VITE_APP_ENV=development
VITE_ENABLE_DEBUG=true
.env.production# Production Environment Variables
VITE_API_BASE_URL=https://api.plotpulse.app/api/v1
VITE_APP_NAME=PlotPulse
VITE_APP_ENV=production
VITE_ENABLE_DEBUG=false
npm run dev → loads .env.developmentnpm run build → loads .env.productionEnvironment variables must be prefixed with VITE_ to be accessible in the app
import.meta.env.VITE_API_BASE_URL or use the config utility:
import { getApiBaseUrl } from './config/env';
const apiUrl = getApiBaseUrl();
The environment configuration is already integrated into:
frontend/src/services/plotService.tsfrontend/src/services/authService.ts# Development build (uses .env.development)
npm run dev
# Production build (uses .env.production)
npm run build
The backend uses Spring Boot profiles to manage environment-specific configurations:
application-dev.ymlapplication-prod.ymlexport SPRING_PROFILES_ACTIVE=prod
mvn spring-boot:run
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=prod"
In your IDE run configuration, add:
Program arguments: --spring.profiles.active=prod
java -jar plotpulse.jar --spring.profiles.active=prod
application-dev.yml (Development)application-prod.yml (Production)Set these environment variables in your production environment:
# Database
export DATABASE_URL=jdbc:postgresql://your-db-host:5432/plotpulse
export DATABASE_USERNAME=your_db_user
export DATABASE_PASSWORD=your_secure_password
# JWT (REQUIRED - generate a new secret for production)
export JWT_SECRET=your_base64_encoded_secret_key
# Server
export SERVER_PORT=8091
export SPRING_PROFILES_ACTIVE=prod
# Frontend URL for CORS
export FRONTEND_URL=https://plotpulse.app
export FRONTEND_URL_WWW=https://www.plotpulse.app
# Application
export APP_BASE_URL=https://api.plotpulse.app/api
To generate a secure JWT secret for production:
# Using OpenSSL
openssl rand -base64 64
# Or using Node.js
node -e "console.log(require('crypto').randomBytes(64).toString('base64'))"
# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ARG VITE_API_BASE_URL
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Build with:
docker build --build-arg VITE_API_BASE_URL=https://api.plotpulse.app/api/v1 -t plotpulse-frontend .
FROM openjdk:17-jdk-slim
WORKDIR /app
COPY target/*.jar app.jar
ENV SPRING_PROFILES_ACTIVE=prod
EXPOSE 8091
ENTRYPOINT ["java", "-jar", "app.jar"]
Run with environment variables:
docker run -e SPRING_PROFILES_ACTIVE=prod \
-e DATABASE_URL=jdbc:postgresql://db:5432/plotpulse \
-e DATABASE_USERNAME=postgres \
-e DATABASE_PASSWORD=secure_password \
-e JWT_SECRET=your_jwt_secret \
plotpulse-backend
| Environment | File | API URL |
|---|---|---|
| Development | .env.development |
http://localhost:8091/api/v1 |
| Production | .env.production |
https://api.plotpulse.app/api/v1 |
| Environment | Profile | Config File |
|---|---|---|
| Development | dev |
application-dev.yml |
| Production | prod |
application-prod.yml |
Frontend:
# Development
npm run dev
# Production build
npm run build
Backend:
# Development
mvn spring-boot:run
# Production
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=prod"
# Or with environment variable
SPRING_PROFILES_ACTIVE=prod mvn spring-boot:run
.env.production or .env.development files to gitVITE_.env filesfrontend/ directorySPRING_PROFILES_ACTIVE environment variableapplication-{profile}.yml files exist${VARIABLE_NAME:default_value} syntax in YAML