Static Frontend Deployment
Guide for deploying docs-angular static build to gograb.space/docs
Static Frontend Deployment Guide
Complete guide for building and deploying the docs-angular static site to gograb.space/docs.
Overview
The docs-angular app can be built as a static Angular application that reads documentation from the backend-docs-api. This allows hosting the frontend separately from the API.
Architecture
flowchart LR
User["User Browser"] -->|HTTPS| StaticSite["gograb.space/docs<br/>(Static Files)"]
StaticSite -->|REST API| DocsAPI["backend-docs-api<br/>Railway"]
DocsAPI -->|Read/Write| MongoDB["MongoDB<br/>test-modules"]
Step 1: Update Production Environment
Ensure production environment points to Railway API:
// apps/docs-angular/src/environments/environment.prod.ts
export const environment = {
production: true,
docsApiUrl: 'https://your-docs-api.railway.app/docs-api',
wsUrl: 'wss://your-docs-api.railway.app',
enableCloudSync: true,
enableAnalytics: true,
};
Step 2: Build Production Bundle
# Build docs-angular for production
nx build docs-angular --configuration=production
Expected output:
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial chunk files | Names | Raw size
main-HASH.js | main | 450.2 kB
polyfills-HASH.js | polyfills | 90.1 kB
styles-HASH.css | styles | 125.3 kB
Output location: dist/apps/docs-angular/browser
Step 3: Test Production Build Locally
# Serve the production build locally
nx serve-static docs-angular
Navigate to http://localhost:5010 and verify:
- App loads correctly
- Documentation pages render
- API calls go to Railway (check Network tab)
- Analytics tracking works
- Search functionality works
Step 4: Deployment Options
Option 1: Copy to Existing gograb.space/docs
If you have access to the gograb.space server:
# Copy build output to server
scp -r dist/apps/docs-angular/browser/* [email protected]:/var/www/gograb.space/docs/
Option 2: Deploy to Railway (Static Site)
Create a new Railway service for static hosting:
# In Railway dashboard:
# 1. Create new service: "docs-angular-static"
# 2. Connect to GitHub repo
# 3. Set build command: nx build docs-angular --configuration=production
# 4. Set start command: npx serve dist/apps/docs-angular/browser -p $PORT
Option 3: Deploy to Vercel
# Install Vercel CLI
npm i -g vercel
# Deploy
cd dist/apps/docs-angular/browser
vercel --prod
Option 4: Deploy to Cloudflare Pages
- Go to Cloudflare Pages dashboard
- Create new project
- Connect to GitHub
- Build settings:
- Build command:
nx build docs-angular --configuration=production - Output directory:
dist/apps/docs-angular/browser
- Build command:
- Deploy
Step 5: Configure Domain
For gograb.space/docs Subdirectory
If deploying to a subdirectory, update the base href:
// apps/docs-angular/src/index.html
<base href="/docs/">
Rebuild:
nx build docs-angular --configuration=production --base-href=/docs/
For Custom Domain
If using a custom domain (e.g., docs.gograb.space):
- Add CNAME record:
docs.gograb.space→ Railway/Vercel/Cloudflare - Update CORS in backend-docs-api:
- Add
https://docs.gograb.spacetoALLOWED_ORIGINS
- Add
- Update environment.prod.ts if needed
Step 6: Verify Production Deployment
Test Checklist
- Navigate to https://gograb.space/docs (or your domain)
- Homepage loads correctly
- Documentation pages render
- Search works (⌘K / Ctrl+K)
- Navigation sidebar works
- Language switching works
- Admin panel loads (if authenticated)
- Analytics tracking works
- API calls succeed (check Network tab)
- WebSocket connects (if applicable)
- No console errors
API Connection Test
Open browser console:
// Test API connection
fetch('https://your-docs-api.railway.app/docs-api/health')
.then(r => r.json())
.then(d => console.log('✅ API Health:', d))
.catch(e => console.error('❌ API Error:', e));
Analytics Test
// Test analytics tracking
fetch('https://your-docs-api.railway.app/docs-api/analytics/page-views', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
path: '/test',
project: 'test',
language: 'en'
})
})
.then(r => r.json())
.then(d => console.log('✅ Analytics tracked:', d))
.catch(e => console.error('❌ Analytics error:', e));
Step 7: Configure CDN (Optional)
For better performance, configure CDN caching:
Cloudflare
- Add page rule for
/docs/* - Cache Level: Standard
- Edge Cache TTL: 2 hours
- Browser Cache TTL: 4 hours
Cache Headers
Configure your server to send:
Cache-Control: public, max-age=3600
For static assets (JS, CSS):
Cache-Control: public, max-age=31536000, immutable
Performance Optimization
Bundle Analysis
# Analyze bundle size
nx build docs-angular --configuration=production --stats-json
# View bundle analyzer
npx webpack-bundle-analyzer dist/apps/docs-angular/browser/stats.json
Optimization Tips
- Enable compression: Gzip/Brotli on server
- Lazy load routes: Already configured
- Image optimization: Use WebP format
- Preload critical assets: Add to index.html
- Service Worker: Consider adding for offline support
Monitoring
Analytics Dashboard
Monitor your deployment:
- Navigate to
/admin/analytics - View real-time usage data
- Export analytics reports
Error Monitoring
Add error tracking (optional):
// In main.ts or app.config.ts
import * as Sentry from '@sentry/angular';
Sentry.init({
dsn: 'your-sentry-dsn',
environment: 'production',
});
Rollback Procedure
If deployment fails:
- Keep previous build:
cp -r dist/apps/docs-angular/browser dist/backup - If issues occur, restore:
cp -r dist/backup/* /var/www/gograb.space/docs/ - Check API logs for errors
- Verify environment variables
Continuous Deployment
GitHub Actions (Optional)
Create .github/workflows/deploy-docs.yml:
name: Deploy Docs
on:
push:
branches: [main]
paths:
- 'apps/docs-angular/**'
- 'docs/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: yarn install
- run: nx build docs-angular --configuration=production
- run: ./deployment/deploy-docs-frontend.sh
Troubleshooting
Build Fails
Problem: Production build fails
Solution:
- Check for TypeScript errors:
nx lint docs-angular - Verify all imports are correct
- Check bundle size limits
- Clear NX cache:
nx reset
API Connection Fails
Problem: Frontend can't connect to API
Solution:
- Verify
environment.prod.tshas correct API URL - Check CORS configuration in backend-docs-api
- Ensure Railway API is deployed and healthy
- Check browser console for CORS errors
Routes Not Working
Problem: Direct URL navigation fails (404)
Solution:
- Configure server for SPA routing
- Add rewrite rules to serve
index.htmlfor all routes - For Nginx:
try_files $uri $uri/ /index.html; - For Apache: Use
.htaccesswith RewriteRule
Assets Not Loading
Problem: CSS/JS files not loading
Solution:
- Check base href is correct
- Verify asset paths in build output
- Check server MIME types
- Review browser console for 404 errors
Performance Benchmarks
Expected Metrics
| Metric | Target | Excellent |
|---|---|---|
| First Contentful Paint | <2s | <1s |
| Time to Interactive | <4s | <2s |
| Total Bundle Size | <2MB | <1.5MB |
| API Response Time | <500ms | <200ms |
Lighthouse Score Targets
- Performance: >90
- Accessibility: >95
- Best Practices: >90
- SEO: >95
Security
Content Security Policy
Add CSP headers:
Content-Security-Policy: default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
connect-src 'self' https://your-docs-api.railway.app;
HTTPS
Ensure all connections use HTTPS in production:
- Frontend:
https://gograb.space/docs - API:
https://your-docs-api.railway.app - WebSocket:
wss://your-docs-api.railway.app
Maintenance
Regular Updates
- Weekly: Check for dependency updates
- Monthly: Review bundle size
- Quarterly: Update Angular version
Monitoring
- Daily: Check error logs
- Weekly: Review analytics data
- Monthly: Performance audit