Production Deployment
Guide to deploying BrewHoard to production environments
This guide covers the steps required to deploy BrewHoard to a production environment.
Build Process
First, build the application for production:
Bash
npm run buildThis command will:
- Compile Svelte components
- Bundle JavaScript and CSS
- Generate static assets
- Create the production-ready application in the
build/directory
Node Adapter Configuration
BrewHoard uses SvelteKit’s Node adapter for server-side rendering. Ensure your svelte.config.js has the correct adapter configuration:
JavaScript
import adapter from '@sveltejs/adapter-node';
export default {
kit: {
adapter: adapter({
// Node adapter options
out: 'build'
})
}
};Environment Variables
Set up the following environment variables for production:
Bash
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/brewhoard_prod
# Authentication
JWT_SECRET=your-secure-jwt-secret
SESSION_SECRET=your-secure-session-secret
# External Services
STRIPE_SECRET_KEY=sk_live_...
GOOGLE_VISION_API_KEY=your-api-key
# App Configuration
ORIGIN=https://yourdomain.com
NODE_ENV=productionDocker Deployment
Use the following Dockerfile for containerized deployment:
Dockerfile
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/build ./build
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "build"]Build and run:
Bash
docker build -t brewhoard .
docker run -p 3000:3000 brewhoardDatabase Setup
- Create a PostgreSQL database for production
- Run migrations:
Bash
npm run migrate- Ensure database backups are configured
- Set up connection pooling if needed
Reverse Proxy (Nginx)
Configure Nginx as a reverse proxy:
Nginx
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}SSL/TLS
Enable HTTPS with Let’s Encrypt:
Bash
sudo certbot --nginx -d yourdomain.comOr configure SSL manually in Nginx:
Nginx
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
# ... rest of config
}Monitoring
Set up monitoring with:
- Application Performance: Use tools like New Relic or DataDog
- Server Monitoring: Configure Prometheus + Grafana
- Error Tracking: Integrate Sentry for error reporting
- Uptime Monitoring: Use services like Pingdom or UptimeRobot
Logging
Configure structured logging:
JavaScript
// In your hooks.server.js
import { dev } from '$app/environment';
export const handle = sequence(
// ... other handlers
logger
);
function logger({ event, resolve }) {
const start = Date.now();
return resolve(event).then(response => {
const duration = Date.now() - start;
console.log(JSON.stringify({
timestamp: new Date().toISOString(),
method: event.request.method,
url: event.url.pathname,
status: response.status,
duration: `${duration}ms`,
userAgent: event.request.headers.get('user-agent')
}));
return response;
});
}Next Steps
- PWA Configuration - Set up Progressive Web App features
- Development Setup - Local development environment
- API Documentation - REST API reference