Skip to content

Commit d278db4

Browse files
committed
update 2025-12-06-running-multiple-apps-under-a-single-domain-with-vercel.md
1 parent 7957695 commit d278db4

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

docs/posts/2025/2025-12-06-running-multiple-apps-under-a-single-domain-with-vercel.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ I own the `copdips.com` domain, and need to point it at several Vercel apps so t
1818
* direct https://app1.vercel.app, still works as before
1919
* direct https://app2.vercel.app, still works as before
2020

21-
In case of redirect, if `app1.vercel.app` serves an HTML file that contains `<link href="/styles.css">`, the browser should load `apps.copdips.com/app1/styles.css`, but not `apps.copdips.com/styles.css` (the root).
22-
2321
This is a standard **Multi-Tenant Routing with Context Awareness** scenario. To serve both the root domain (`app1.vercel.app`) and the subpath version (`apps.copdips.com/app1`) from the same deployment, each app must become host-aware-effectively detecting whether the request comes through the main router or directly and adjusting asset URLs and links accordingly.
2422

2523
<!-- more -->
2624

25+
In case of redirect, if `app1.vercel.app` serves an HTML file that contains `<link href="/styles.css">`, the browser should load `apps.copdips.com/app1/styles.css`, but not `apps.copdips.com/styles.css` (the root).
26+
2727
```mermaid
2828
graph TD
2929
User[User Browser]
@@ -106,7 +106,27 @@ On the main domain (`apps.copdips.com`), configure `vercel.json`:
106106

107107
2. For MkDocs Apps
108108

109-
If your MkDocs site uses `use_directory_urls: true` (hides `.html`), you need explicit `index.html` rewrites:
109+
??? tip "Setting up MkDocs for Vercel"
110+
MkDocs projects run smoothly on Vercel too. For a reference implementation, check [fu-sen/Vercel-MkDocs](https://github.com/fu-sen/Vercel-MkDocs). The idea is simple: compile the static site so the output lives under `public/`, and Vercel serves that directory automatically.
111+
112+
Core steps:
113+
114+
1. in `package.json`, add a build script to build MkDocs site into `public/` in Vercel:
115+
```json title="package.json in MkDocs App" hl_lines="7"
116+
{
117+
"name": "mkdocs",
118+
"version": "1.0.0",
119+
"private": true,
120+
"scripts": {
121+
"dev": "mkdocs serve",
122+
"build": "python3 -m mkdocs build -d public"
123+
}
124+
}
125+
```
126+
2. Add `requirements.txt` to root with all the mkdocs python dependencies. Vercel will auto-install them.
127+
3. In Vercel project settings, set **Framework Preset** to **Other** and keep the remaining options at their defaults.
128+
129+
When `use_directory_urls: true` is enabled in `mkdocs.yml` (so `.html` extensions stay hidden), add explicit `index.html` rewrites as shown below:
110130

111131
```json title="vercel.json in Router App for MkDocs"
112132
{
@@ -128,7 +148,7 @@ On the main domain (`apps.copdips.com`), configure `vercel.json`:
128148
}
129149
```
130150

131-
If using `use_directory_urls: false` (shows `.html`), use the simple SPA config above-no special `index.html` handling needed.
151+
If you keep `use_directory_urls: false` (so `.html` remains visible), the basic SPA rewrite setup is enoughno extra `index.html` rules required.
132152

133153
**Note:** `trailingSlash: true` in the router's `vercel.json` works for both React and MkDocs apps.
134154

@@ -140,8 +160,6 @@ On the main domain (`apps.copdips.com`), configure `vercel.json`:
140160

141161
**Result:** One deployment, multiple URLs. Simple.
142162

143-
---
144-
145163
## Real Example
146164

147165
My [OAuth2/OIDC Visualizer](https://apps.copdips.com/oauth2-oidc-visualizer/) works at both:

0 commit comments

Comments
 (0)