-
Notifications
You must be signed in to change notification settings - Fork 5
/
middleware.ts
22 lines (19 loc) · 928 Bytes
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* This file is a Vercel Edge Middleware.
* @see https://vercel.com/docs/functions/edge-middleware
*
* Since "xzd.me" is the common domain used by the root package and sub-package `studio`,
* they are accessed via different pathnames (i.e., "/" for the root package and "/studio" for sub-package `studio`),
* and since they are deployed separately on Vercel as two different projects,
* this file is used to redirect all requests starting with `/studio` from this Vercel project to the other Vercel project for `studio`.
*/
import { rewrite } from '@vercel/edge'
export default function middleware(request: Request) {
const url = new URL(request.url)
if (url.pathname.startsWith('/studio')) {
// eslint-disable-next-line node/prefer-global/process
const baseUrl = process.env.SANITY_STUDIO_SITE_DOMAIN
if (baseUrl)
return rewrite(new URL(url.pathname, baseUrl))
}
}