Skip to content

Commit 9cec115

Browse files
authored
Document scalable subdomains (#1126)
* Update Cloudflare page * update CloudFront page * update vercel * add vercel json generator * add repo structure section to all pages
1 parent 3d2ddb6 commit 9cec115

File tree

4 files changed

+136
-21
lines changed

4 files changed

+136
-21
lines changed

advanced/subpath/cloudflare.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
---
22
title: "Cloudflare"
3-
description: "Host documentation at a /docs subpath using Cloudflare Workers"
3+
description: "Host documentation at a custom subpath using Cloudflare Workers"
44
---
55

66
import Propagating from "/snippets/custom-subpath-propagating.mdx";
77

8-
To host your documentation at a `/docs` subpath using Cloudflare, you will need to create and configure a Cloudflare Worker.
8+
To host your documentation at a custom subpath such as `yoursite.com/docs` using Cloudflare, you will need to create and configure a Cloudflare Worker.
99

1010
<Info>
1111
Before you begin, you need a Cloudflare account and a domain name (can be managed on or off Cloudflare).
1212
</Info>
1313

14+
## Repository structure
15+
16+
Your documentation files must be organized within your repository to match your chosen subpath structure. For example, if you want your documentation at `yoursite.com/docs`, you would create a `docs/` directory with all of your documentation files.
17+
1418
## Set up a Cloudflare Worker
1519

1620
Create a Cloudflare Worker by following the [Cloudflare Workers getting started guide](https://developers.cloudflare.com/workers/get-started/dashboard/), if you have not already.
@@ -43,7 +47,7 @@ Ensure that the `HOST` header is correctly forwarded in your Worker configuratio
4347
In your Cloudflare dashboard, select **Edit Code** and add the following script into your Worker's code. See the [Cloudflare documentation](https://developers.cloudflare.com/workers-ai/get-started/dashboard/#development) for more information on editing a Worker.
4448

4549
<Tip>
46-
Replace `[SUBDOMAIN]` with your unique subdomain and `[YOUR_DOMAIN]` with your website's base URL.
50+
Replace `[SUBDOMAIN]` with your unique subdomain, `[YOUR_DOMAIN]` with your website's base URL, and `/docs` with your desired subpath if different.
4751
</Tip>
4852

4953
```javascript
@@ -128,7 +132,7 @@ If you use Webflow to host your main site and want to serve Mintlify docs at `/d
128132
3. To avoid conflicts, update any absolute URLs in your main site to be relative.
129133
4. In Cloudflare, select **Edit Code** and add the following script into your Worker's code.
130134

131-
<Tip> Replace `[SUBDOMAIN]` with your unique subdomain, `[YOUR_DOMAIN]` with your website's base URL, and `[LANDING_DOMAIN]` with your landing page URL. </Tip>
135+
<Tip> Replace `[SUBDOMAIN]` with your unique subdomain, `[YOUR_DOMAIN]` with your website's base URL, `[LANDING_DOMAIN]` with your landing page URL, and `/docs` with your desired subpath if different. </Tip>
132136

133137
```javascript
134138
addEventListener("fetch", (event) => {

advanced/subpath/route53-cloudfront.mdx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
22
title: "AWS Route 53 and CloudFront"
33
sidebarTitle: "AWS"
4-
description: "Host documentation at a /docs subdirectory using AWS services"
4+
description: "Host documentation at a custom subpath using AWS services"
55
---
66

77
import Propagating from "/snippets/custom-subpath-propagating.mdx";
88

9-
To host your documentation at a `/docs` subpath using AWS Route 53 and CloudFront, you need to configure your DNS provider to point to your CloudFront distribution.
9+
To host your documentation at a custom subpath such as `yoursite.com/docs` using AWS Route 53 and CloudFront, you need to configure your DNS provider to point to your CloudFront distribution.
10+
11+
## Repository structure
12+
13+
Your documentation files must be organized within your repository to match your chosen subpath structure. For example, if you want your documentation at `yoursite.com/docs`, you would create a `docs/` directory with all of your documentation files.
1014

1115
## High-level overview
1216

@@ -80,9 +84,9 @@ By this point, you should have two Origins: one with `[SUBDOMAIN].mintlify.app`
8084

8185
## Set behaviors
8286

83-
Behaviors in CloudFront enable control over the subpath logic. At a high level, we're looking to create the following logic.
87+
Behaviors in CloudFront enable control over the subpath logic. At a high level, we're looking to create the following logic:
8488

85-
- **If a user lands on /docs**, go to `[SUBDOMAIN].mintlify.dev`.
89+
- **If a user lands on your custom subpath**, go to `[SUBDOMAIN].mintlify.dev`.
8690
- **If a user lands on any other page**, go the current landing page.
8791

8892
1. Navigate to the "Behaviors" tab of your CloudFront distribution.
@@ -109,9 +113,9 @@ If `.well-known/*` is too generic, it can be narrowed down to 2 behaviors at a m
109113
- `/.well-known/acme-challenge/*` - Required for Let's Encrypt certificate verification
110114
</Info>
111115

112-
### `/docs`
116+
### Your custom subpath
113117

114-
Create a behavior with a **Path pattern** of `/docs` with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`).
118+
Create a behavior with a **Path pattern** of your chosen subpath, for example `/docs`, with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`).
115119

116120
- Set "Cache policy" to **CachingOptimized**.
117121
- Set "Origin request policy" to **AllViewerExceptHostHeader**.
@@ -121,11 +125,11 @@ Create a behavior with a **Path pattern** of `/docs` with **Origin and origin gr
121125
![CloudFront "Create behavior" page with a "Path pattern" of "/docs/*" and "Origin and origin groups" pointing to the `acme.mintlify.dev` URL.](/images/cloudfront/behavior-1.png)
122126
</Frame>
123127

124-
### `/docs/*`
128+
### Your custom subpath with wildcard
125129

126-
Create a behavior with a **Path pattern** of `/docs/*` and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.
130+
Create a behavior with a **Path pattern** of your chosen subpath followed by `/*`, for example `/docs/*`, and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.
127131

128-
These settings should exactly match `/docs`. With the exception of the **Path pattern**.
132+
These settings should exactly match your base subpath behavior. With the exception of the **Path pattern**.
129133

130134
- Set "Cache policy" to **CachingOptimized**.
131135
- Set "Origin request policy" to **AllViewerExceptHostHeader**.
@@ -169,7 +173,7 @@ You can now test if your distribution is set up properly by going to the "Genera
169173
![CloudFront "General" tab with the "Distribution domain name" URL highlighted.](/images/cloudfront/preview-distribution.png)
170174
</Frame>
171175

172-
All pages should be directing to your main landing page, but if you append `/docs` to the URL, you should see it going to your Mintlify documentation instance.
176+
All pages should be directing to your main landing page, but if you append your chosen subpath, for example `/docs`, to the URL, you should see it going to your Mintlify documentation instance.
173177

174178
## Connect with Route53
175179

@@ -201,6 +205,6 @@ Now, we're going to bring the functionality of the CloudFront distribution into
201205
You may need to remove the existing A record if one currently exists.
202206
</Note>
203207

204-
Your documentation is now live at `/docs` for your primary domain.
208+
Your documentation is now live at your chosen subpath for your primary domain.
205209

206210
<Propagating />

advanced/subpath/vercel.mdx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
---
22
title: "Vercel"
3-
description: "Host documentation at a /docs subpath using Vercel"
3+
description: "Host documentation at a custom subpath using Vercel"
44
---
55

6+
import { VercelJsonGenerator } from "/snippets/vercel-json-generator.mdx";
7+
68
## vercel.json file
79

8-
The `vercel.json` file is Vercel's configuration file that allows you to customize how your project is built and deployed. It sits in your project's root directory and controls various aspects of your deployment, including routing, redirects, headers, and build settings.
10+
The `vercel.json` file configures how your project is built and deployed. It sits in your project's root directory and controls various aspects of your deployment, including routing, redirects, headers, and build settings.
911

1012
We use the `rewrites` configuration to proxy requests from your main domain to your documentation.
1113

12-
Rewrites allow you to map incoming requests to different destinations without changing the URL in the browser. When someone visits `yoursite.com/docs`, Vercel will internally fetch content from `your-subdomain.mintlify.dev/docs` but the user will still see `yoursite.com/docs` in their browser. This is different from redirects, which would send users to a different URL entirely.
14+
Rewrites map incoming requests to different destinations without changing the URL in the browser. When someone visits `yoursite.com/docs`, Vercel will internally fetch content from `your-subdomain.mintlify.dev/docs` but the user will still see `yoursite.com/docs` in their browser. This is different from redirects, which would send users to a different URL entirely.
15+
16+
You can customize the subpath to any value you prefer, such as `/docs`, `/help`, or `/guides`. Additionally, you can use deeply nested subpaths like `/product/docs`.
17+
18+
## Repository structure
19+
20+
Your documentation files must be organized within your repository to match your chosen subpath structure. For example, if you want your documentation at `yoursite.com/docs`, you would create a `docs/` directory with all of your documentation files.
1321

1422
## Configuration
1523

16-
To host your documentation at a custom `/docs` subpath using Vercel, add the following configuration to your `vercel.json` file:
24+
To host your documentation at a custom subpath using Vercel, add the following configuration to your `vercel.json` file. This example uses `/docs`, but you can replace it with any subpath:
1725

1826
```json
1927
{
@@ -32,11 +40,16 @@ To host your documentation at a custom `/docs` subpath using Vercel, add the fol
3240

3341
- **`source`**: The path pattern on your domain that triggers the rewrite.
3442
- **`destination`**: Where the request should be proxied to.
35-
- **`:match*`**: A wildcard that captures any path segments after `/docs/`.
36-
43+
- **`:match*`**: A wildcard that captures any path segments after your subpath.
3744

3845
For more information, see [Configuring projects with vercel.json: Rewrites](https://vercel.com/docs/projects/project-configuration#rewrites) in the Vercel documentation.
3946

47+
### Generate rewrites
48+
49+
Enter your subdomain and custom subdirectory to generate the rewrites for your `vercel.json` file.
50+
51+
<VercelJsonGenerator />
52+
4053
## Using external proxies with Vercel
4154

4255
If you're using an external proxy (like Cloudflare or AWS CloudFront) in front of your Vercel deployment, you must configure it properly to avoid conflicts with Vercel's domain verification and SSL certificate provisioning.

snippets/vercel-json-generator.mdx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
export const VercelJsonGenerator = () => {
2+
const [subdomain, setSubdomain] = useState('[SUBDOMAIN]')
3+
const [subdirectory, setSubdirectory] = useState('docs')
4+
5+
const vercelConfig = {
6+
rewrites: [
7+
{
8+
source: "/api/request",
9+
destination: `https://${subdomain}.mintlify.app/api/request`
10+
},
11+
{
12+
source: `/${subdirectory}`,
13+
destination: `https://${subdomain}.mintlify.app`
14+
},
15+
{
16+
source: `/${subdirectory}/llms.txt`,
17+
destination: `https://${subdomain}.mintlify.app/llms.txt`
18+
},
19+
{
20+
source: `/${subdirectory}/llms-full.txt`,
21+
destination: `https://${subdomain}.mintlify.app/llms-full.txt`
22+
},
23+
{
24+
source: `/${subdirectory}/sitemap.xml`,
25+
destination: `https://${subdomain}.mintlify.app/sitemap.xml`
26+
},
27+
{
28+
source: `/${subdirectory}/robots.txt`,
29+
destination: `https://${subdomain}.mintlify.app/robots.txt`
30+
},
31+
{
32+
source: `/${subdirectory}/:path*`,
33+
destination: `https://${subdomain}.mintlify.app/${subdirectory}/:path*`
34+
},
35+
{
36+
source: "/mintlify-assets/:path+",
37+
destination: `https://${subdomain}.mintlify.app/mintlify-assets/:path+`
38+
}
39+
]
40+
}
41+
42+
const copyToClipboard = () => {
43+
navigator.clipboard
44+
.writeText(JSON.stringify(vercelConfig, null, 2))
45+
.then(() => {
46+
console.log('Copied config to clipboard!')
47+
})
48+
.catch((err) => {
49+
console.error("Failed to copy: ", err)
50+
})
51+
}
52+
53+
return (
54+
<div className="p-4 border dark:border-white/10 rounded-2xl not-prose space-y-4">
55+
<div className="space-y-4">
56+
<div>
57+
<label className="block text-sm text-zinc-950/70 dark:text-white/70 mb-1">
58+
Subdomain
59+
</label>
60+
<input
61+
type="text"
62+
value={subdomain}
63+
onChange={(e) => setSubdomain(e.target.value)}
64+
placeholder="your-subdomain"
65+
className="w-full p-1 text-sm rounded border dark:border-white/10 bg-transparent"
66+
/>
67+
</div>
68+
<div>
69+
<label className="block text-sm text-zinc-950/70 dark:text-white/70 mb-1">
70+
Subdirectory
71+
</label>
72+
<input
73+
type="text"
74+
value={subdirectory}
75+
onChange={(e) => setSubdirectory(e.target.value)}
76+
placeholder="docs"
77+
className="w-full p-1 text-sm rounded border dark:border-white/10 bg-transparent"
78+
/>
79+
</div>
80+
</div>
81+
<div className="relative">
82+
<button
83+
onClick={copyToClipboard}
84+
className="absolute top-2 right-2 px-2 py-1 text-sm border dark:border-white/10 rounded hover:bg-zinc-950/5 dark:hover:bg-white/5 transition-colors bg-white"
85+
>
86+
Copy to Clipboard
87+
</button>
88+
<pre className="bg-zinc-950/5 dark:bg-white/5 p-4 rounded-lg overflow-auto text-xs">
89+
<code>{JSON.stringify(vercelConfig, null, 2)}</code>
90+
</pre>
91+
</div>
92+
</div>
93+
)
94+
}

0 commit comments

Comments
 (0)