@rsc-kit/mcp 0.41.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +18 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +270 -216
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
package/guides/domains.md
CHANGED
|
@@ -2,66 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
> A host as a route segment — admin.example.com reaches app/admin, a tenant's host binds [domain] — with nothing to rewrite.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
`
|
|
7
|
-
|
|
8
|
-
router's own, so the build can see it: typed routes, one stored page per
|
|
9
|
-
tenant, and no middleware to write.
|
|
10
|
-
|
|
11
|
-
## The rule
|
|
12
|
-
|
|
13
|
-
A request from a host that is not the site's own is matched **with the host
|
|
14
|
-
in front of the path**:
|
|
15
|
-
|
|
16
|
-
| request | matched as | file |
|
|
17
|
-
| --- | --- | --- |
|
|
18
|
-
| `example.com/admin` | `/admin` | `app/admin/page.tsx` |
|
|
19
|
-
| `admin.example.com/` | `/admin` | `app/admin/page.tsx` — the same file |
|
|
20
|
-
| `acme.example.com/settings` | `/acme/settings` | `app/[domain]/settings/page.tsx`, `domain: "acme"` |
|
|
21
|
-
| `acme.com/settings` | `/acme.com/settings` | the same file, `domain: "acme.com"` |
|
|
22
|
-
|
|
23
|
-
A subdomain of the site contributes its label; any other host contributes the
|
|
24
|
-
whole host. The site's own hosts — the one in the root layout's
|
|
25
|
-
`metadataBase`, `www.` of it, and any named in `rscKit({ hosts })` — contribute
|
|
26
|
-
nothing, so the apex keeps path routing and an app adds tenants without moving
|
|
27
|
-
a file. `localhost` and an ip address are always the site's own.
|
|
28
|
-
|
|
29
|
-
Listing a subdomain in `hosts` makes it the site by path instead of a tenant —
|
|
30
|
-
the "app on `app.example.com`, marketing on the apex" split — which is a
|
|
31
|
-
choice, not a requirement.
|
|
32
|
-
|
|
33
|
-
And only when a route could answer it: a `[domain]` (or `[host]`) directory at
|
|
34
|
-
the top of `app/`, or a directory named for the host. Any other parameter
|
|
35
|
-
name at the top of `app/` — `[collection]`, `[slug]` — is a path segment, as
|
|
36
|
-
it is in Next. An app with no tenant tree routes every host by path, and a proxy that forwards to the app by an internal name is not
|
|
37
|
-
read as a tenant called `internal`.
|
|
38
|
-
|
|
39
|
-
A subdomain of the site with no directory of its name falls back the same
|
|
40
|
-
way: with no `app/merchant/`, `merchant.example.com/` serves the home page.
|
|
41
|
-
That keeps a preview deployment under the production domain working. The dev
|
|
42
|
-
server says so once per host, naming the directory to add:
|
|
5
|
+
A subdomain is a folder. Name the site's own host once, and
|
|
6
|
+
`admin.example.com` is served by `app/admin/`, the same pages as
|
|
7
|
+
`example.com/admin`:
|
|
43
8
|
|
|
9
|
+
```ts title="vite.config.ts"
|
|
10
|
+
rscKit({ hosts: ['example.com'] })
|
|
44
11
|
```
|
|
45
|
-
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
src/app/
|
|
15
|
+
page.tsx example.com/
|
|
16
|
+
admin/
|
|
17
|
+
page.tsx admin.example.com/ and example.com/admin
|
|
18
|
+
[domain]/
|
|
19
|
+
settings/
|
|
20
|
+
page.tsx acme.example.com/settings, acme.com/settings
|
|
46
21
|
```
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`acme.example.com/billing`. Only the match changed.
|
|
23
|
+
There is no middleware to write and no rewrite. The router matches the host
|
|
24
|
+
itself, so typed links, stored pages and the build all see it.
|
|
51
25
|
|
|
52
|
-
##
|
|
26
|
+
## Naming the site's host
|
|
53
27
|
|
|
54
|
-
The router has to know which host is the site
|
|
55
|
-
|
|
56
|
-
neither is needed for anything else here. Name neither and no host is the
|
|
57
|
-
site's: `merchant.example.com` is then a foreign host whose segment is the
|
|
58
|
-
whole name, no directory matches it, and it is served by path — the home page,
|
|
59
|
-
with nothing said.
|
|
28
|
+
The router has to know which host is the site. It learns it from
|
|
29
|
+
`rscKit({ hosts })` or from the root layout's `metadataBase`. One is enough.
|
|
60
30
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
machine running it — `example.test` under Herd, the real domain in
|
|
64
|
-
production — is the one named:
|
|
31
|
+
When the address is in the environment, as a Laravel app's is in `APP_URL`,
|
|
32
|
+
read it in the Vite config:
|
|
65
33
|
|
|
66
34
|
```ts title="vite.config.ts"
|
|
67
35
|
import { defineConfig, loadEnv } from 'vite'
|
|
@@ -75,27 +43,80 @@ export default defineConfig(({ mode }) => {
|
|
|
75
43
|
})
|
|
76
44
|
```
|
|
77
45
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
absolute against — and a computed one is not read for routing. An app with no
|
|
81
|
-
such metadata needs none.
|
|
46
|
+
The build reads it, so the address of the machine running it is the one named:
|
|
47
|
+
`example.test` under Herd, the real domain in production.
|
|
82
48
|
|
|
83
|
-
`hosts` also takes
|
|
84
|
-
|
|
85
|
-
second brand domain:
|
|
49
|
+
`hosts` also takes names that are the site rather than a tenant: a staging or
|
|
50
|
+
internal name, or a second brand domain:
|
|
86
51
|
|
|
87
52
|
```ts title="vite.config.ts"
|
|
88
|
-
rscKit({ hosts: ['app.internal', 'example.co.uk'] })
|
|
53
|
+
rscKit({ hosts: ['example.com', 'app.internal', 'example.co.uk'] })
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A literal `metadataBase` works too, but a computed one isn't read for routing.
|
|
57
|
+
It's meant for metadata: the base a relative Open Graph image or canonical URL
|
|
58
|
+
is made absolute against.
|
|
59
|
+
|
|
60
|
+
If you name neither, no host is the site's. `merchant.example.com` is then a
|
|
61
|
+
foreign host, no folder matches it, and it is served by path: the home page,
|
|
62
|
+
with nothing said.
|
|
63
|
+
|
|
64
|
+
## Serving a subdomain from a folder
|
|
65
|
+
|
|
66
|
+
Add a folder named for the subdomain:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
src/app/
|
|
70
|
+
merchant/
|
|
71
|
+
page.tsx merchant.example.com/
|
|
72
|
+
orders/
|
|
73
|
+
page.tsx merchant.example.com/orders
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A request from a host that isn't the site's own is matched with the host in
|
|
77
|
+
front of the path:
|
|
78
|
+
|
|
79
|
+
| Request | Matched as | File |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| `example.com/admin` | `/admin` | `app/admin/page.tsx` |
|
|
82
|
+
| `admin.example.com/` | `/admin` | `app/admin/page.tsx`, the same file |
|
|
83
|
+
| `acme.example.com/settings` | `/acme/settings` | `app/[domain]/settings/page.tsx`, `domain: "acme"` |
|
|
84
|
+
| `acme.com/settings` | `/acme.com/settings` | the same file, `domain: "acme.com"` |
|
|
85
|
+
|
|
86
|
+
- A subdomain of the site adds its label. Any other host adds the whole host.
|
|
87
|
+
- The site's own hosts add nothing, so the apex keeps routing by path. They
|
|
88
|
+
are the one in `metadataBase`, `www.` of it, and any named in `hosts`.
|
|
89
|
+
- `localhost` and an IP address are always the site's own.
|
|
90
|
+
- Listing a subdomain in `hosts` makes it the site, routed by path, rather than
|
|
91
|
+
a tenant. That's the "app on `app.example.com`, marketing on the apex" split.
|
|
92
|
+
|
|
93
|
+
The visitor's URL doesn't change. `acme.example.com/settings` stays in the
|
|
94
|
+
address bar, and a link to `/billing` on that page goes to
|
|
95
|
+
`acme.example.com/billing`. Only the match changed.
|
|
96
|
+
|
|
97
|
+
### A subdomain with no folder
|
|
98
|
+
|
|
99
|
+
A subdomain of the site with no folder of its name is served by path, so
|
|
100
|
+
`merchant.example.com/` with no `app/merchant/` serves the home page. That
|
|
101
|
+
keeps a preview deployment under the production domain working. The dev server
|
|
102
|
+
says so once per host, naming the folder to add:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
[rsc-kit] merchant.example.test has no app/merchant/ - served by path, as the site's own. Add app/merchant/ to route the subdomain there.
|
|
89
106
|
```
|
|
90
107
|
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
Host routing only applies when a route could answer it: a `[domain]` (or
|
|
109
|
+
`[host]`) folder at the top of `app/`, or a folder named for the host. Any
|
|
110
|
+
other parameter at the top of `app/`, such as `[collection]` or `[slug]`, is a
|
|
111
|
+
path segment. An app with no tenant tree routes every host by path, so a proxy
|
|
112
|
+
that forwards to the app by an internal name isn't read as a tenant called
|
|
113
|
+
`internal`.
|
|
93
114
|
|
|
94
|
-
##
|
|
115
|
+
## Serving tenants from `[domain]`
|
|
95
116
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Its argument is the route's params:
|
|
117
|
+
A `[domain]` folder at the top of `app/` receives the tenant's host. Check that
|
|
118
|
+
the tenant exists in `middleware.ts`. It runs before anything is sent, on every
|
|
119
|
+
path, and its `notFound()` is a real 404. Its argument is the route's params:
|
|
99
120
|
|
|
100
121
|
```ts title="src/app/[domain]/middleware.ts"
|
|
101
122
|
import { notFound } from '@rsc-kit/core/not-found';
|
|
@@ -106,10 +127,23 @@ export default async function knownTenant({ domain }) {
|
|
|
106
127
|
}
|
|
107
128
|
```
|
|
108
129
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
130
|
+
A page reads the tenant from `params`:
|
|
131
|
+
|
|
132
|
+
```tsx title="src/app/[domain]/settings/page.tsx"
|
|
133
|
+
import { tenantByDomain } from '@/lib/tenants';
|
|
134
|
+
|
|
135
|
+
export default async function SettingsPage({ params }) {
|
|
136
|
+
const { domain } = await params;
|
|
137
|
+
const tenant = await tenantByDomain(domain);
|
|
138
|
+
|
|
139
|
+
return <h1>{tenant!.name} settings</h1>;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The layout gets the same params, as a promise. A route that lists no URLs is
|
|
144
|
+
stored as one shell for every tenant, so put the part that reads the tenant
|
|
145
|
+
under `<Suspense>`. Awaited above every boundary, there's no value to store the
|
|
146
|
+
shell with, and the build says so and names the layout:
|
|
113
147
|
|
|
114
148
|
```tsx title="src/app/[domain]/layout.tsx"
|
|
115
149
|
import { Suspense } from 'react';
|
|
@@ -135,33 +169,28 @@ export default function TenantLayout({ params, children }) {
|
|
|
135
169
|
}
|
|
136
170
|
```
|
|
137
171
|
|
|
138
|
-
|
|
139
|
-
one's, and it is rendered again when one of its own values changes:
|
|
140
|
-
`acme.example.com/settings` to `globex.example.com/settings` renders the
|
|
141
|
-
tenant layout for globex, while the root layout above it stays mounted.
|
|
172
|
+
`[domain]` is an ordinary dynamic segment otherwise:
|
|
142
173
|
|
|
143
|
-
`
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
`
|
|
147
|
-
|
|
174
|
+
- `params.domain` is in every page and layout below it, and `error.tsx` and
|
|
175
|
+
`loading.tsx` work where you put them.
|
|
176
|
+
- A layout is rendered again when one of its own values changes.
|
|
177
|
+
`acme.example.com/settings` to `globex.example.com/settings` renders the
|
|
178
|
+
tenant layout for globex, and the root layout above it stays mounted.
|
|
179
|
+
- A folder named for a host, such as `app/admin/`, wins over `[domain]`, the
|
|
180
|
+
way a static segment wins over a parameter anywhere else.
|
|
148
181
|
|
|
149
|
-
One difference
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
reached as `example.com/acme`. Next has no such guard — its `[domain]` folder
|
|
153
|
-
matches any path once the rewrite is in place — which is why Next apps tuck
|
|
154
|
-
the tenant tree under a route group.
|
|
182
|
+
One difference: a `[domain]` at the top of `app/` binds **only from a host**,
|
|
183
|
+
never from a path. `example.com/nope` is a 404, not a tenant called `nope`, and
|
|
184
|
+
`acme.example.com/` can't be reached as `example.com/acme`.
|
|
155
185
|
|
|
156
186
|
## Linking to another host
|
|
157
187
|
|
|
158
|
-
A typed `href` is a folder path
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
to be seen on `merchant.example.com`, say so with `hostUrl`:
|
|
188
|
+
A typed `href` is a folder path, so `/merchant/orders` links to the site by
|
|
189
|
+
path. Both addresses work. When the page is meant to be seen on its subdomain,
|
|
190
|
+
link with `hostUrl`:
|
|
162
191
|
|
|
163
192
|
```tsx title="src/app/page.tsx"
|
|
164
|
-
import
|
|
193
|
+
import Link from '@rsc-kit/core/Link';
|
|
165
194
|
import { hostUrl } from '@rsc-kit/core/routes';
|
|
166
195
|
|
|
167
196
|
<Link href={hostUrl('merchant', '/orders')}>Orders</Link> // //merchant.example.com/orders
|
|
@@ -171,65 +200,72 @@ import { hostUrl } from '@rsc-kit/core/routes';
|
|
|
171
200
|
```
|
|
172
201
|
|
|
173
202
|
- The first argument autocompletes to the top-level folders of `app/`, and
|
|
174
|
-
takes any other string too
|
|
175
|
-
|
|
203
|
+
takes any other string too, such as a tenant's subdomain read from the
|
|
204
|
+
database. A name with a dot is a whole domain, used as written.
|
|
176
205
|
- The path is typed by what that host answers. For a folder it is the pages
|
|
177
|
-
under it, with the folder taken off
|
|
206
|
+
under it, with the folder taken off: `hostUrl('merchant', '/orders')`, not
|
|
178
207
|
`'/merchant/orders'`. For any other name it is the tenant tree's paths.
|
|
179
208
|
- With one argument it is the site itself: the link back from a subdomain,
|
|
180
209
|
where a plain `/pricing` would stay on the subdomain.
|
|
181
210
|
|
|
182
|
-
|
|
183
|
-
`metadataBase` otherwise), port and all, so `hosts: [new URL(env.APP_URL).host]`
|
|
184
|
-
gives `merchant.example.test` under Herd and `merchant.example.com` in
|
|
185
|
-
production. With no host named, a folder's url is its path,
|
|
186
|
-
`/merchant/orders`, since every page is then reached by path.
|
|
211
|
+
It works in `visit()` and `redirect()` too:
|
|
187
212
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
```ts
|
|
214
|
+
redirect(hostUrl(tenant.slug, '/welcome'));
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The site's host is the first one `hosts` names (or a literal `metadataBase`),
|
|
218
|
+
port included. So `hosts: [new URL(env.APP_URL).host]` gives
|
|
219
|
+
`merchant.example.test` under Herd and `merchant.example.com` in production.
|
|
220
|
+
With no host named, a folder's URL is its path, `/merchant/orders`.
|
|
192
221
|
|
|
193
|
-
|
|
222
|
+
The URL is the same string on the server and in the browser, so the link
|
|
223
|
+
hydrates as it was rendered. On the host it already names, `Link` navigates
|
|
224
|
+
without a reload. To another host it is a full page load, as any link to
|
|
225
|
+
another origin is.
|
|
194
226
|
|
|
195
|
-
##
|
|
227
|
+
## Keeping a folder on its subdomain only
|
|
196
228
|
|
|
197
|
-
When a folder is only ever meant to be seen on its subdomain
|
|
198
|
-
dashboard
|
|
229
|
+
When a folder is only ever meant to be seen on its subdomain, such as a
|
|
230
|
+
merchant dashboard or an admin, name it in `subdomains`. Its subdomain becomes
|
|
231
|
+
the page's only URL:
|
|
199
232
|
|
|
200
233
|
```ts title="vite.config.ts"
|
|
201
234
|
rscKit({ hosts: [new URL(env.APP_URL).host], subdomains: ['merchant'] })
|
|
202
235
|
```
|
|
203
236
|
|
|
204
237
|
- `example.com/merchant/orders` answers 301 to `merchant.example.com/orders`,
|
|
205
|
-
query kept.
|
|
206
|
-
preview or a platform's own name (`<app>.homeport.run`) the path form still
|
|
207
|
-
renders and links keep it, since there is no subdomain of those to go to.
|
|
238
|
+
with the query kept.
|
|
208
239
|
- `<Link href="/merchant/orders">`, `visit('/merchant/orders')` and
|
|
209
|
-
`redirect('/merchant/orders')` go to `merchant.example.com/orders
|
|
210
|
-
href stays the folder path, and the host is
|
|
211
|
-
- On the subdomain, a root path that
|
|
240
|
+
`redirect('/merchant/orders')` go to `merchant.example.com/orders`. The typed
|
|
241
|
+
href stays the folder path, and the host is added for you, with no `hostUrl`.
|
|
242
|
+
- On the subdomain, a root path that isn't under the folder is the site's:
|
|
212
243
|
`<Link href="/pricing">` goes to `example.com/pricing`.
|
|
213
|
-
-
|
|
214
|
-
|
|
215
|
-
visitors there send `/auth`, never `/merchant/auth`.
|
|
216
|
-
- The build's route table lists the folder, so a backend that names routes
|
|
217
|
-
puts them on the subdomain - Laravel's `route('merchant.orders')` is
|
|
244
|
+
- The build's route table lists the folder, so a backend that names routes puts
|
|
245
|
+
them on the subdomain. Laravel's `route('merchant.orders')` is
|
|
218
246
|
`https://merchant.example.com/orders`.
|
|
219
247
|
|
|
220
|
-
The
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
248
|
+
The redirect and the links only apply on the site's own host. On `localhost`,
|
|
249
|
+
an IP address, a preview or a platform's own name (`<app>.homeport.run`), the
|
|
250
|
+
path form still renders and links keep it, since there is no subdomain of
|
|
251
|
+
those to go to.
|
|
252
|
+
|
|
253
|
+
`example.com/merchant` is then no longer a page of the site: it is the
|
|
254
|
+
subdomain's home page. Put a landing page about merchants in a folder of its
|
|
255
|
+
own, such as `app/sell/`. `subdomains` needs the site's host (`hosts`) and a
|
|
256
|
+
folder of that name, or dev and the build stop and say which is missing.
|
|
257
|
+
|
|
258
|
+
Two things the build enforces:
|
|
226
259
|
|
|
227
|
-
|
|
260
|
+
- `edge.json` lists none of the folder's pages. An edge answers by path and
|
|
261
|
+
would skip the 301.
|
|
262
|
+
- A `backendPaths` entry under the folder stops the build, because visitors
|
|
263
|
+
there send `/auth`, never `/merchant/auth`.
|
|
228
264
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
265
|
+
## Building a page per tenant
|
|
266
|
+
|
|
267
|
+
List the tenants in `generateStaticParams` on the tenant route. Each listed
|
|
268
|
+
host is rendered at build and stored, one file per host:
|
|
233
269
|
|
|
234
270
|
```ts title="src/app/[domain]/page.tsx"
|
|
235
271
|
export async function generateStaticParams() {
|
|
@@ -239,41 +275,46 @@ export async function generateStaticParams() {
|
|
|
239
275
|
}
|
|
240
276
|
```
|
|
241
277
|
|
|
242
|
-
A
|
|
243
|
-
|
|
278
|
+
A host added later falls through to the plain tree or, if the page reads the
|
|
279
|
+
request, renders on demand. A tenant's page that reads `cookies()` or awaits
|
|
280
|
+
`connection()` is dynamic for that tenant and stored for none, like any page.
|
|
281
|
+
|
|
282
|
+
## Trying it locally
|
|
244
283
|
|
|
245
|
-
|
|
284
|
+
`localhost` and an IP address are always the site's own, so a dev server
|
|
285
|
+
opened on one routes by path as usual. A local name such as `example.test`
|
|
286
|
+
under Herd or Valet is a host like any other: `merchant.example.test` reaches
|
|
287
|
+
`app/merchant/` only when `example.test` is named in `hosts`. Reading
|
|
288
|
+
`APP_URL`, as above, does that. A `metadataBase` fixed to the production host
|
|
289
|
+
names only that one.
|
|
246
290
|
|
|
247
|
-
|
|
248
|
-
opened on one routes by path as it always did. A local name is not:
|
|
249
|
-
`example.test` under Herd or Valet is a host like any other, and
|
|
250
|
-
`merchant.example.test` reaches `app/merchant/` only when `example.test` is
|
|
251
|
-
named in `hosts` — which reading `APP_URL`, as above, does. A `metadataBase`
|
|
252
|
-
fixed to the production host names only that one. To try a tenant
|
|
253
|
-
without DNS, send the host the router will see in production:
|
|
291
|
+
To try a tenant without DNS, send the host the router will see in production:
|
|
254
292
|
|
|
255
293
|
```bash
|
|
256
294
|
curl -H 'X-Forwarded-Host: acme.example.com' http://localhost:3000/
|
|
257
295
|
```
|
|
258
296
|
|
|
259
|
-
Or point `acme.example.com` at `127.0.0.1` in `/etc/hosts` and open it on
|
|
260
|
-
|
|
297
|
+
Or point `acme.example.com` at `127.0.0.1` in `/etc/hosts` and open it on the
|
|
298
|
+
dev server's port.
|
|
261
299
|
|
|
262
300
|
## Behind a proxy
|
|
263
301
|
|
|
264
302
|
The host is read from `X-Forwarded-Host` first, then `Host`. A load balancer
|
|
265
|
-
that terminates TLS and forwards to the app by an internal name still routes
|
|
266
|
-
|
|
303
|
+
that terminates TLS and forwards to the app by an internal name still routes by
|
|
304
|
+
the name the visitor typed.
|
|
267
305
|
|
|
268
|
-
##
|
|
306
|
+
## Static exports
|
|
269
307
|
|
|
270
308
|
An export is served by a file server, which sees no host. Host routing is a
|
|
271
|
-
server feature
|
|
309
|
+
server feature, so an exported site is the site's own on every host it is
|
|
272
310
|
served from.
|
|
273
311
|
|
|
274
312
|
## Coming from Next
|
|
275
313
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
`
|
|
279
|
-
|
|
314
|
+
Next routes a subdomain with a `middleware.ts` that rewrites
|
|
315
|
+
`acme.example.com/settings` to `/acme/settings`. Delete that rewrite, and the
|
|
316
|
+
`[domain]` folder works as it did: the segment binds the same value. Next's
|
|
317
|
+
`[domain]` folder also matches any path once the rewrite is in place, which is
|
|
318
|
+
why Next apps tuck the tenant tree under a route group. Here it binds only from
|
|
319
|
+
a host, so it doesn't need one. Next's `rewrite()` for anything else isn't
|
|
320
|
+
here: a host maps to a tree by file, not by code.
|