Vercel
Host Jamdesk docs at a /docs subpath using Vercel rewrites
Use Vercel rewrites to proxy documentation requests to Jamdesk. Rewrites happen at the edge and don't change the URL in the browser.
Prerequisites
- A project deployed on Vercel
- Your Jamdesk subdomain (found in dashboard settings)
Step 1: Update vercel.json
Add a rewrites configuration to your vercel.json file. If the file doesn't exist, create it in your project root:
{
"rewrites": [
{
"source": "/docs",
"destination": "https://YOUR_SLUG.jamdesk.app/docs"
},
{
"source": "/docs/:path*",
"destination": "https://YOUR_SLUG.jamdesk.app/docs/:path*"
}
]
}Replace YOUR_SLUG with your actual Jamdesk subdomain (e.g., acme if your docs are at acme.jamdesk.app).
Step 2: Deploy
Deploy your changes to Vercel:
vercel --prod
Or push to your connected Git repository to trigger an automatic deployment.
Step 3: Verify
Visit https://yoursite.com/docs to confirm your documentation is being served correctly.
Understanding the Configuration
| Property | Description |
|---|---|
source | The path pattern on your domain that triggers the rewrite |
destination | The URL to proxy the request to |
:path* | A wildcard that captures all path segments after /docs/ |
The two rewrite rules handle:
- The base
/docspath (e.g.,yoursite.com/docs) - All nested paths (e.g.,
yoursite.com/docs/getting-started)
Adding to Existing Rewrites
If you already have rewrites configured, add the Jamdesk rules to your existing array:
{
"rewrites": [
{ "source": "/api/:path*", "destination": "/api/:path*" },
{ "source": "/docs", "destination": "https://YOUR_SLUG.jamdesk.app/docs" },
{ "source": "/docs/:path*", "destination": "https://YOUR_SLUG.jamdesk.app/docs/:path*" }
]
}Rewrite order matters. Place more specific rules before general ones.
Using next.config.js (Next.js Projects)
For Next.js projects, you can alternatively configure rewrites in next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
return [
{
source: "/docs",
destination: "https://YOUR_SLUG.jamdesk.app/docs",
},
{
source: "/docs/:path*",
destination: "https://YOUR_SLUG.jamdesk.app/docs/:path*",
},
];
},
};
export default nextConfig;Troubleshooting
Ensure vercel.json is in your project root and properly formatted. Check the Vercel deployment logs for configuration errors.
Verify you have both rewrite rules - one for /docs and one for /docs/:path*. Missing the wildcard rule causes nested pages to fail.
Check that your destination URL uses https:// and points to jamdesk.app, not your own domain.
Custom Domain Verification
Vercel rewrites work by proxying requests to your Jamdesk subdomain (YOUR_SLUG.jamdesk.app). This basic setup doesn't require domain verification.
If you've configured a custom domain in the Jamdesk dashboard with the "Host at /docs" option, you'll need to use Edge Middleware instead of simple rewrites to set the required verification header.
Using Edge Middleware
Create a middleware.ts file in your project root:
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
const JAMDESK_HOST = 'YOUR_SLUG.jamdesk.app';
export function middleware(request: NextRequest) {
const url = request.nextUrl;
// Only proxy /docs paths
if (!url.pathname.startsWith('/docs')) {
return NextResponse.next();
}
// Rewrite to Jamdesk
const destination = new URL(url.pathname + url.search, `https://${JAMDESK_HOST}`);
const response = NextResponse.rewrite(destination);
// Required for domain verification
response.headers.set('X-Jamdesk-Forwarded-Host', url.hostname);
return response;
}
export const config = {
matcher: '/docs/:path*',
};Replace YOUR_SLUG with your actual Jamdesk subdomain.
The X-Jamdesk-Forwarded-Host header is required for domain verification. Your domain must be verified in the Jamdesk dashboard before the middleware will serve content.
When to Use Middleware vs Rewrites
| Approach | Use When |
|---|---|
| Rewrites | Basic setup without custom domain verification |
| Edge Middleware | Custom domain with "Host at /docs" option enabled |
If you don't need custom domain verification, the simpler rewrites approach is sufficient.
