Documentation Deployment Guide
This guide covers deploying the VitePress documentation to Cloudflare Workers.
Why Cloudflare Workers?
As of 2024-2025, Cloudflare recommends using Workers for all new projects, including static sites:
- Unified Platform: Both your app and docs on the same infrastructure
- Better Performance: Edge computing with zero cold starts
- Static Asset Support: Workers now support static asset hosting
- Advanced Features: Headers manipulation, redirects, authentication
Prerequisites
- Cloudflare account
- Wrangler CLI installed
- Domain configured in Cloudflare (for custom domain)
Deployment Steps
1. Build Documentation
npm run docs:buildThis creates optimized static files in dist-docs/.
2. Deploy to Cloudflare Workers
npm run docs:deployThis command:
- Builds the documentation
- Deploys to Cloudflare Workers using
wrangler-docs.toml
3. Configure Custom Domain
After first deployment:
- Go to Cloudflare Dashboard → Workers & Pages
- Find your
imperium-docsworker - Go to Settings → Triggers
- Add custom domain:
docs.maledictum.jatoft.se
Or use Wrangler CLI:
wrangler domains add docs.maledictum.jatoft.se --config wrangler-docs.tomlConfiguration Files
docs-worker.js
The worker handles:
- Static asset serving from KV
- Proper routing for VitePress
- Security headers
- 404 handling
wrangler-docs.toml
name = "imperium-docs"
main = "docs-worker.js"
compatibility_date = "2024-01-01"
[site]
bucket = "./dist-docs"
[env.production]
route = "docs.maledictum.jatoft.se/*"Development Workflow
Local Development
# Start VitePress dev server
npm run docs:devVisit http://localhost:5173
Preview with Worker
# Build and preview with Wrangler
npm run docs:worker:devVisit http://localhost:8787
Continuous Deployment
GitHub Actions
Create .github/workflows/deploy-docs.yml:
name: Deploy Documentation
on:
push:
branches: [main]
paths:
- 'docs/**'
- 'docs-worker.js'
- 'wrangler-docs.toml'
- 'package.json'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build documentation
run: npm run docs:build
- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
command: deploy --config wrangler-docs.tomlRequired Secrets
Add to GitHub repository settings:
CLOUDFLARE_API_TOKEN: Create at https://dash.cloudflare.com/profile/api-tokens- Required permissions:
- Account: Cloudflare Workers Scripts:Edit
- Zone: Workers Routes:Edit (if using custom domain)
- Required permissions:
Environment-Specific Deployments
Staging Environment
Create wrangler-docs-staging.toml:
name = "imperium-docs-staging"
main = "docs-worker.js"
compatibility_date = "2024-01-01"
[site]
bucket = "./dist-docs"
[env.staging]
route = "docs-staging.maledictum.jatoft.se/*"
[vars]
ENVIRONMENT = "staging"Deploy to staging:
wrangler deploy --config wrangler-docs-staging.toml --env stagingPerformance Optimization
Caching Strategy
The docs worker implements aggressive caching:
cacheControl: {
browserTTL: 60 * 60 * 24 * 365, // 1 year for assets
edgeTTL: 60 * 60 * 24 * 30, // 30 days on edge
bypassCache: false,
}Cache Purging
After deploying updates:
# Purge all cache
wrangler cache purge --all
# Purge specific paths
wrangler cache purge "/guide/*" "/api/*"Monitoring
Analytics
View in Cloudflare Dashboard:
- Workers & Pages → imperium-docs
- Analytics tab
Real-time Logs
wrangler tail --config wrangler-docs.tomlTroubleshooting
Common Issues
1. Asset Not Found
Check that dist-docs contains built files:
ls -la dist-docs/2. Routing Issues
VitePress generates .html files. The worker handles:
/guide→/guide.html/guide/installation→/guide/installation.html
3. Build Failures
Clear cache and rebuild:
rm -rf docs/.vitepress/cache docs/.vitepress/dist dist-docs
npm run docs:build4. Domain Not Working
Check DNS settings:
dig docs.maledictum.jatoft.seShould point to Cloudflare's edge network.
Security Headers
The worker adds security headers automatically:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockReferrer-Policy: strict-origin-when-cross-origin
Advanced Features
Password Protection
Add basic auth to docs-worker.js:
async function handleRequest(event) {
const authorization = event.request.headers.get('Authorization');
if (!authorization || !checkAuth(authorization)) {
return new Response('Unauthorized', {
status: 401,
headers: {
'WWW-Authenticate': 'Basic realm="Documentation"'
}
});
}
// Continue with normal handling...
}Redirects
Add to worker for URL changes:
const redirects = {
'/old-path': '/new-path',
'/guide/setup': '/guide/installation'
};
if (redirects[url.pathname]) {
return Response.redirect(url.origin + redirects[url.pathname], 301);
}Cost Considerations
Workers Free Tier (as of 2025)
- 100,000 requests/day
- 10ms CPU time per request
- Unlimited static asset requests
Documentation typically uses:
- ~1ms CPU time per request
- Minimal bandwidth
- Well within free tier limits
Next Steps
- Deploy documentation:
npm run docs:deploy - Configure custom domain
- Set up GitHub Actions
- Monitor analytics
- Add search functionality