Repository navigation
Expand file tree
/
Copy pathvercel.ts
More file actions
174 lines (158 loc) · 4.7 KB
/
Copy pathvercel.ts
File metadata and controls
174 lines (158 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const DOC_DISCOVERY_LINK_VALUE = [
'</.well-known/api-catalog>; rel="api-catalog"; type="application/linkset+json"',
'</.well-known/mcp.json>; rel="describedby"; type="application/json"',
'</.well-known/agent-skills/index.json>; rel="describedby"; type="application/json"',
'</llms.txt>; rel="alternate"; type="text/plain"',
'</llms-full.txt>; rel="alternate"; type="text/plain"',
].join(", ");
const OPENAPI_DISCOVERY_LINK_VALUE = [
'</.well-known/api-catalog>; rel="api-catalog"; type="application/linkset+json"',
'</.well-known/mcp.json>; rel="describedby"; type="application/json"',
'</.well-known/agent-skills/index.json>; rel="describedby"; type="application/json"',
].join(", ");
const MPP_SERVICES_MCP_WORKER_ORIGIN =
process.env.MPP_SERVICES_MCP_WORKER_ORIGIN?.replace(/\/+$/, "");
if (
!MPP_SERVICES_MCP_WORKER_ORIGIN &&
process.env.VERCEL_ENV === "production"
) {
throw new Error(
"MPP_SERVICES_MCP_WORKER_ORIGIN is required for production Vercel builds",
);
}
const REWRITES = [
...(MPP_SERVICES_MCP_WORKER_ORIGIN
? [
rewriteRule(
"/mcp/services",
`${MPP_SERVICES_MCP_WORKER_ORIGIN}/mcp/services`,
),
rewriteRule(
"/mcp/services/:path*",
`${MPP_SERVICES_MCP_WORKER_ORIGIN}/mcp/services`,
),
]
: []),
];
const CONTENT_NEGOTIATION_HEADERS = [header("Vary", "Accept, User-Agent")];
const API_CATALOG_HEADERS = [
header("Access-Control-Allow-Origin", "*"),
header("Cache-Control", "public, max-age=300"),
header(
"Content-Type",
'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"',
),
header(
"Link",
'</.well-known/api-catalog>; rel="api-catalog"; type="application/linkset+json"',
),
header("X-Content-Type-Options", "nosniff"),
];
const CACHE_HEADERS = [
header("Cache-Control", "public, max-age=300"),
header("X-Content-Type-Options", "nosniff"),
];
const STATIC_ASSET_CACHE_HEADERS = [
header(
"Cache-Control",
"public, max-age=86400, s-maxage=604800, stale-while-revalidate=2592000",
),
];
const STATIC_ASSET_SOURCES = [
"/playground/fonts/:path*",
"/fonts/:path*",
"/icons/:path*",
"/lottie/:path*",
"/marketing/:path*",
"/vendor/:path*",
];
const DOC_SECTIONS = [
"advanced",
"blog",
"extensions",
"guides",
"intents",
"overview",
"partner-integrations",
"payment-methods",
"protocol",
"quickstart",
"sdk",
"services",
"tools",
"use-cases",
];
const DOC_STANDALONE_PAGES = ["/brand", "/faq", "/governance", "/mpp-vs-x402"];
const DISCOVERY_PAGE_SOURCES = [
"/",
...DOC_STANDALONE_PAGES,
...DOC_SECTIONS.flatMap((section) => [`/${section}`, `/${section}/:path*`]),
];
export const config = {
headers: [
headerRule("/.well-known/api-catalog", API_CATALOG_HEADERS),
headerRule("/.well-known/:path*", [
header("Access-Control-Allow-Origin", "*"),
...CACHE_HEADERS,
]),
headerRule("/robots.txt", CACHE_HEADERS),
headerRule("/rss.xml", [
header("Content-Type", "application/rss+xml; charset=utf-8"),
...CACHE_HEADERS,
]),
headerRule("/services/catalog.json", [
header(
"Cache-Control",
"public, max-age=300, s-maxage=3600, stale-while-revalidate=86400",
),
]),
// The playgrounds' content-hashed assets (scripts/copy-playground.ts).
headerRule("/playground/assets/:path*", [
header("Cache-Control", "public, max-age=31536000, immutable"),
]),
...STATIC_ASSET_SOURCES.map((source) =>
headerRule(source, STATIC_ASSET_CACHE_HEADERS),
),
headerRule("/openapi.json", [header("Link", OPENAPI_DISCOVERY_LINK_VALUE)]),
...DISCOVERY_PAGE_SOURCES.map((source) =>
headerRule(source, [
header("Link", DOC_DISCOVERY_LINK_VALUE),
...CONTENT_NEGOTIATION_HEADERS,
]),
),
// Content-hashed service logos (scripts/build-logos.ts). Last, so it wins
// over the /services/:path* rule above.
headerRule("/services/logos/:path*", [
header("Cache-Control", "public, max-age=31536000, immutable"),
header("Vary", "Accept-Encoding"),
]),
],
...(REWRITES.length > 0 ? { rewrites: REWRITES } : {}),
redirects: [
{
source: "/index",
destination: "/",
permanent: true,
},
{
source: "/openapi.json",
destination: "/api/openapi.json",
permanent: false,
},
{
source: "/:path(.*)",
has: [{ type: "host", value: "mpp.tempo.xyz" }],
destination: "https://mpp.dev/:path",
permanent: true,
},
],
};
function header(key, value) {
return { key, value };
}
function headerRule(source, headers) {
return { source, headers };
}
function rewriteRule(source, destination) {
return { source, destination };
}