@vercel/routing-utils 2.2.1 → 3.1.0
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/append.js +62 -41
- package/dist/index.js +339 -282
- package/dist/merge.js +106 -88
- package/dist/schemas.d.ts +7 -0
- package/dist/schemas.js +315 -275
- package/dist/superstatic.js +312 -300
- package/dist/types.d.ts +1 -0
- package/dist/types.js +15 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -1,318 +1,375 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
15
17
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
appendRoutesToPhase: () => import_append.appendRoutesToPhase,
|
|
23
|
+
getCleanUrls: () => import_superstatic2.getCleanUrls,
|
|
24
|
+
getTransformedRoutes: () => getTransformedRoutes,
|
|
25
|
+
isHandler: () => isHandler,
|
|
26
|
+
isValidHandleValue: () => isValidHandleValue,
|
|
27
|
+
mergeRoutes: () => import_merge.mergeRoutes,
|
|
28
|
+
normalizeRoutes: () => normalizeRoutes
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
var import_url = require("url");
|
|
32
|
+
var import_superstatic = require("./superstatic");
|
|
33
|
+
var import_append = require("./append");
|
|
34
|
+
var import_merge = require("./merge");
|
|
35
|
+
__reExport(src_exports, require("./schemas"), module.exports);
|
|
36
|
+
var import_superstatic2 = require("./superstatic");
|
|
37
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
28
38
|
const VALID_HANDLE_VALUES = [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
"filesystem",
|
|
40
|
+
"hit",
|
|
41
|
+
"miss",
|
|
42
|
+
"rewrite",
|
|
43
|
+
"error",
|
|
44
|
+
"resource"
|
|
35
45
|
];
|
|
36
46
|
const validHandleValues = new Set(VALID_HANDLE_VALUES);
|
|
37
47
|
function isHandler(route) {
|
|
38
|
-
|
|
48
|
+
return typeof route.handle !== "undefined";
|
|
39
49
|
}
|
|
40
|
-
exports.isHandler = isHandler;
|
|
41
50
|
function isValidHandleValue(handle) {
|
|
42
|
-
|
|
51
|
+
return validHandleValues.has(handle);
|
|
43
52
|
}
|
|
44
|
-
exports.isValidHandleValue = isValidHandleValue;
|
|
45
53
|
function normalizeRoutes(inputRoutes) {
|
|
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
|
-
|
|
54
|
+
if (!inputRoutes || inputRoutes.length === 0) {
|
|
55
|
+
return { routes: inputRoutes, error: null };
|
|
56
|
+
}
|
|
57
|
+
const routes = [];
|
|
58
|
+
const handling = [];
|
|
59
|
+
const errors = [];
|
|
60
|
+
inputRoutes.forEach((r, i) => {
|
|
61
|
+
const route = { ...r };
|
|
62
|
+
routes.push(route);
|
|
63
|
+
const keys = Object.keys(route);
|
|
64
|
+
if (isHandler(route)) {
|
|
65
|
+
const { handle } = route;
|
|
66
|
+
if (keys.length !== 1) {
|
|
67
|
+
const unknownProp = keys.find((prop) => prop !== "handle");
|
|
68
|
+
errors.push(
|
|
69
|
+
`Route at index ${i} has unknown property \`${unknownProp}\`.`
|
|
70
|
+
);
|
|
71
|
+
} else if (!isValidHandleValue(handle)) {
|
|
72
|
+
errors.push(
|
|
73
|
+
`Route at index ${i} has unknown handle value \`handle: ${handle}\`.`
|
|
74
|
+
);
|
|
75
|
+
} else if (handling.includes(handle)) {
|
|
76
|
+
errors.push(
|
|
77
|
+
`Route at index ${i} is a duplicate. Please use one \`handle: ${handle}\` at most.`
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
handling.push(handle);
|
|
81
|
+
}
|
|
82
|
+
} else if (route.src) {
|
|
83
|
+
if (!route.src.startsWith("^")) {
|
|
84
|
+
route.src = `^${route.src}`;
|
|
85
|
+
}
|
|
86
|
+
if (!route.src.endsWith("$")) {
|
|
87
|
+
route.src = `${route.src}$`;
|
|
88
|
+
}
|
|
89
|
+
route.src = route.src.replace(/\\\//g, "/");
|
|
90
|
+
const regError = checkRegexSyntax("Route", i, route.src);
|
|
91
|
+
if (regError) {
|
|
92
|
+
errors.push(regError);
|
|
93
|
+
}
|
|
94
|
+
const handleValue = handling[handling.length - 1];
|
|
95
|
+
if (handleValue === "hit") {
|
|
96
|
+
if (route.dest) {
|
|
97
|
+
errors.push(
|
|
98
|
+
`Route at index ${i} cannot define \`dest\` after \`handle: hit\`.`
|
|
99
|
+
);
|
|
71
100
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
// Route src should always end with a '$'
|
|
78
|
-
if (!route.src.endsWith('$')) {
|
|
79
|
-
route.src = `${route.src}$`;
|
|
80
|
-
}
|
|
81
|
-
// Route src should strip escaped forward slash, its not special
|
|
82
|
-
route.src = route.src.replace(/\\\//g, '/');
|
|
83
|
-
const regError = checkRegexSyntax('Route', i, route.src);
|
|
84
|
-
if (regError) {
|
|
85
|
-
errors.push(regError);
|
|
86
|
-
}
|
|
87
|
-
// The last seen handling is the current handler
|
|
88
|
-
const handleValue = handling[handling.length - 1];
|
|
89
|
-
if (handleValue === 'hit') {
|
|
90
|
-
if (route.dest) {
|
|
91
|
-
errors.push(`Route at index ${i} cannot define \`dest\` after \`handle: hit\`.`);
|
|
92
|
-
}
|
|
93
|
-
if (route.status) {
|
|
94
|
-
errors.push(`Route at index ${i} cannot define \`status\` after \`handle: hit\`.`);
|
|
95
|
-
}
|
|
96
|
-
if (!route.continue) {
|
|
97
|
-
errors.push(`Route at index ${i} must define \`continue: true\` after \`handle: hit\`.`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else if (handleValue === 'miss') {
|
|
101
|
-
if (route.dest && !route.check) {
|
|
102
|
-
errors.push(`Route at index ${i} must define \`check: true\` after \`handle: miss\`.`);
|
|
103
|
-
}
|
|
104
|
-
else if (!route.dest && !route.continue) {
|
|
105
|
-
errors.push(`Route at index ${i} must define \`continue: true\` after \`handle: miss\`.`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
101
|
+
if (route.status) {
|
|
102
|
+
errors.push(
|
|
103
|
+
`Route at index ${i} cannot define \`status\` after \`handle: hit\`.`
|
|
104
|
+
);
|
|
108
105
|
}
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
if (!route.continue) {
|
|
107
|
+
errors.push(
|
|
108
|
+
`Route at index ${i} must define \`continue: true\` after \`handle: hit\`.`
|
|
109
|
+
);
|
|
111
110
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
} else if (handleValue === "miss") {
|
|
112
|
+
if (route.dest && !route.check) {
|
|
113
|
+
errors.push(
|
|
114
|
+
`Route at index ${i} must define \`check: true\` after \`handle: miss\`.`
|
|
115
|
+
);
|
|
116
|
+
} else if (!route.dest && !route.continue) {
|
|
117
|
+
errors.push(
|
|
118
|
+
`Route at index ${i} must define \`continue: true\` after \`handle: miss\`.`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
errors.push(
|
|
124
|
+
`Route at index ${i} must define either \`handle\` or \`src\` property.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const error = errors.length > 0 ? createError(
|
|
129
|
+
"invalid_route",
|
|
130
|
+
errors,
|
|
131
|
+
"https://vercel.link/routes-json",
|
|
132
|
+
"Learn More"
|
|
133
|
+
) : null;
|
|
134
|
+
return { routes, error };
|
|
117
135
|
}
|
|
118
|
-
exports.normalizeRoutes = normalizeRoutes;
|
|
119
136
|
function checkRegexSyntax(type, index, src) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return null;
|
|
137
|
+
try {
|
|
138
|
+
new RegExp(src);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
const prop = type === "Route" ? "src" : "source";
|
|
141
|
+
return `${type} at index ${index} has invalid \`${prop}\` regular expression "${src}".`;
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
128
144
|
}
|
|
129
|
-
function checkPatternSyntax(type, index, {
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
function checkPatternSyntax(type, index, {
|
|
146
|
+
source,
|
|
147
|
+
destination,
|
|
148
|
+
has
|
|
149
|
+
}) {
|
|
150
|
+
let sourceSegments = /* @__PURE__ */ new Set();
|
|
151
|
+
const destinationSegments = /* @__PURE__ */ new Set();
|
|
152
|
+
try {
|
|
153
|
+
sourceSegments = new Set((0, import_superstatic.sourceToRegex)(source).segments);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return {
|
|
156
|
+
message: `${type} at index ${index} has invalid \`source\` pattern "${source}".`,
|
|
157
|
+
link: "https://vercel.link/invalid-route-source-pattern"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (destination) {
|
|
132
161
|
try {
|
|
133
|
-
|
|
162
|
+
const { hostname, pathname, query } = (0, import_url.parse)(destination, true);
|
|
163
|
+
(0, import_superstatic.sourceToRegex)(hostname || "").segments.forEach(
|
|
164
|
+
(name) => destinationSegments.add(name)
|
|
165
|
+
);
|
|
166
|
+
(0, import_superstatic.sourceToRegex)(pathname || "").segments.forEach(
|
|
167
|
+
(name) => destinationSegments.add(name)
|
|
168
|
+
);
|
|
169
|
+
for (const strOrArray of Object.values(query)) {
|
|
170
|
+
const value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray;
|
|
171
|
+
(0, import_superstatic.sourceToRegex)(value || "").segments.forEach(
|
|
172
|
+
(name) => destinationSegments.add(name)
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
} catch (err) {
|
|
134
176
|
}
|
|
135
|
-
|
|
177
|
+
const hasSegments = (0, import_superstatic.collectHasSegments)(has);
|
|
178
|
+
for (const segment of destinationSegments) {
|
|
179
|
+
if (!sourceSegments.has(segment) && !hasSegments.includes(segment)) {
|
|
136
180
|
return {
|
|
137
|
-
|
|
138
|
-
|
|
181
|
+
message: `${type} at index ${index} has segment ":${segment}" in \`destination\` property but not in \`source\` or \`has\` property.`,
|
|
182
|
+
link: "https://vercel.link/invalid-route-destination-segment"
|
|
139
183
|
};
|
|
184
|
+
}
|
|
140
185
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const { hostname, pathname, query } = (0, url_1.parse)(destination, true);
|
|
144
|
-
(0, superstatic_1.sourceToRegex)(hostname || '').segments.forEach(name => destinationSegments.add(name));
|
|
145
|
-
(0, superstatic_1.sourceToRegex)(pathname || '').segments.forEach(name => destinationSegments.add(name));
|
|
146
|
-
for (const strOrArray of Object.values(query)) {
|
|
147
|
-
const value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray;
|
|
148
|
-
(0, superstatic_1.sourceToRegex)(value || '').segments.forEach(name => destinationSegments.add(name));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
// Since checkPatternSyntax() is a validation helper, we don't want to
|
|
153
|
-
// replicate all possible URL parsing here so we consume the error.
|
|
154
|
-
// If this really is an error, we'll throw later in convertRedirects().
|
|
155
|
-
}
|
|
156
|
-
const hasSegments = (0, superstatic_1.collectHasSegments)(has);
|
|
157
|
-
for (const segment of destinationSegments) {
|
|
158
|
-
if (!sourceSegments.has(segment) && !hasSegments.includes(segment)) {
|
|
159
|
-
return {
|
|
160
|
-
message: `${type} at index ${index} has segment ":${segment}" in \`destination\` property but not in \`source\` or \`has\` property.`,
|
|
161
|
-
link: 'https://vercel.link/invalid-route-destination-segment',
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
167
188
|
}
|
|
168
189
|
function checkRedirect(r, index) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return null;
|
|
190
|
+
if (typeof r.permanent !== "undefined" && typeof r.statusCode !== "undefined") {
|
|
191
|
+
return `Redirect at index ${index} cannot define both \`permanent\` and \`statusCode\` properties.`;
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
174
194
|
}
|
|
175
195
|
function createError(code, allErrors, link, action) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
196
|
+
const errors = Array.isArray(allErrors) ? allErrors : [allErrors];
|
|
197
|
+
const message = errors[0];
|
|
198
|
+
const error = {
|
|
199
|
+
name: "RouteApiError",
|
|
200
|
+
code,
|
|
201
|
+
message,
|
|
202
|
+
link,
|
|
203
|
+
action,
|
|
204
|
+
errors
|
|
205
|
+
};
|
|
206
|
+
return error;
|
|
187
207
|
}
|
|
188
208
|
function notEmpty(value) {
|
|
189
|
-
|
|
209
|
+
return value !== null && value !== void 0;
|
|
190
210
|
}
|
|
191
211
|
function getTransformedRoutes(vercelConfig) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return normalizeRoutes(routes);
|
|
212
|
+
const { cleanUrls, rewrites, redirects, headers, trailingSlash } = vercelConfig;
|
|
213
|
+
let { routes = null } = vercelConfig;
|
|
214
|
+
if (routes) {
|
|
215
|
+
const hasNewProperties = typeof cleanUrls !== "undefined" || typeof trailingSlash !== "undefined" || typeof redirects !== "undefined" || typeof headers !== "undefined" || typeof rewrites !== "undefined";
|
|
216
|
+
if (hasNewProperties) {
|
|
217
|
+
const error = createError(
|
|
218
|
+
"invalid_mixed_routes",
|
|
219
|
+
"If `rewrites`, `redirects`, `headers`, `cleanUrls` or `trailingSlash` are used, then `routes` cannot be present.",
|
|
220
|
+
"https://vercel.link/mix-routing-props",
|
|
221
|
+
"Learn More"
|
|
222
|
+
);
|
|
223
|
+
return { routes, error };
|
|
205
224
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
225
|
+
return normalizeRoutes(routes);
|
|
226
|
+
}
|
|
227
|
+
if (typeof cleanUrls !== "undefined") {
|
|
228
|
+
const normalized = normalizeRoutes(
|
|
229
|
+
(0, import_superstatic.convertCleanUrls)(cleanUrls, trailingSlash)
|
|
230
|
+
);
|
|
231
|
+
if (normalized.error) {
|
|
232
|
+
normalized.error.code = "invalid_clean_urls";
|
|
233
|
+
return { routes, error: normalized.error };
|
|
214
234
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
235
|
+
routes = routes || [];
|
|
236
|
+
routes.push(...normalized.routes || []);
|
|
237
|
+
}
|
|
238
|
+
if (typeof trailingSlash !== "undefined") {
|
|
239
|
+
const normalized = normalizeRoutes((0, import_superstatic.convertTrailingSlash)(trailingSlash));
|
|
240
|
+
if (normalized.error) {
|
|
241
|
+
normalized.error.code = "invalid_trailing_slash";
|
|
242
|
+
return { routes, error: normalized.error };
|
|
223
243
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
routes,
|
|
241
|
-
error: createError(code, patternError.message, patternError.link, 'Learn More'),
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
const redirectErrorMessage = redirects.map(checkRedirect).find(notEmpty);
|
|
245
|
-
if (redirectErrorMessage) {
|
|
246
|
-
return {
|
|
247
|
-
routes,
|
|
248
|
-
error: createError(code, redirectErrorMessage, 'https://vercel.link/redirects-json', 'Learn More'),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const normalized = normalizeRoutes((0, superstatic_1.convertRedirects)(redirects));
|
|
252
|
-
if (normalized.error) {
|
|
253
|
-
normalized.error.code = code;
|
|
254
|
-
return { routes, error: normalized.error };
|
|
255
|
-
}
|
|
256
|
-
routes = routes || [];
|
|
257
|
-
routes.push(...(normalized.routes || []));
|
|
244
|
+
routes = routes || [];
|
|
245
|
+
routes.push(...normalized.routes || []);
|
|
246
|
+
}
|
|
247
|
+
if (typeof redirects !== "undefined") {
|
|
248
|
+
const code = "invalid_redirect";
|
|
249
|
+
const regexErrorMessage = redirects.map((r, i) => checkRegexSyntax("Redirect", i, r.source)).find(notEmpty);
|
|
250
|
+
if (regexErrorMessage) {
|
|
251
|
+
return {
|
|
252
|
+
routes,
|
|
253
|
+
error: createError(
|
|
254
|
+
"invalid_redirect",
|
|
255
|
+
regexErrorMessage,
|
|
256
|
+
"https://vercel.link/invalid-route-source-pattern",
|
|
257
|
+
"Learn More"
|
|
258
|
+
)
|
|
259
|
+
};
|
|
258
260
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const patternError = headers
|
|
271
|
-
.map((r, i) => checkPatternSyntax('Header', i, r))
|
|
272
|
-
.find(notEmpty);
|
|
273
|
-
if (patternError) {
|
|
274
|
-
return {
|
|
275
|
-
routes,
|
|
276
|
-
error: createError(code, patternError.message, patternError.link, 'Learn More'),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
const normalized = normalizeRoutes((0, superstatic_1.convertHeaders)(headers));
|
|
280
|
-
if (normalized.error) {
|
|
281
|
-
normalized.error.code = code;
|
|
282
|
-
return { routes, error: normalized.error };
|
|
283
|
-
}
|
|
284
|
-
routes = routes || [];
|
|
285
|
-
routes.push(...(normalized.routes || []));
|
|
261
|
+
const patternError = redirects.map((r, i) => checkPatternSyntax("Redirect", i, r)).find(notEmpty);
|
|
262
|
+
if (patternError) {
|
|
263
|
+
return {
|
|
264
|
+
routes,
|
|
265
|
+
error: createError(
|
|
266
|
+
code,
|
|
267
|
+
patternError.message,
|
|
268
|
+
patternError.link,
|
|
269
|
+
"Learn More"
|
|
270
|
+
)
|
|
271
|
+
};
|
|
286
272
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
routes
|
|
313
|
-
|
|
314
|
-
|
|
273
|
+
const redirectErrorMessage = redirects.map(checkRedirect).find(notEmpty);
|
|
274
|
+
if (redirectErrorMessage) {
|
|
275
|
+
return {
|
|
276
|
+
routes,
|
|
277
|
+
error: createError(
|
|
278
|
+
code,
|
|
279
|
+
redirectErrorMessage,
|
|
280
|
+
"https://vercel.link/redirects-json",
|
|
281
|
+
"Learn More"
|
|
282
|
+
)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const normalized = normalizeRoutes((0, import_superstatic.convertRedirects)(redirects));
|
|
286
|
+
if (normalized.error) {
|
|
287
|
+
normalized.error.code = code;
|
|
288
|
+
return { routes, error: normalized.error };
|
|
289
|
+
}
|
|
290
|
+
routes = routes || [];
|
|
291
|
+
routes.push(...normalized.routes || []);
|
|
292
|
+
}
|
|
293
|
+
if (typeof headers !== "undefined") {
|
|
294
|
+
const code = "invalid_header";
|
|
295
|
+
const regexErrorMessage = headers.map((r, i) => checkRegexSyntax("Header", i, r.source)).find(notEmpty);
|
|
296
|
+
if (regexErrorMessage) {
|
|
297
|
+
return {
|
|
298
|
+
routes,
|
|
299
|
+
error: createError(
|
|
300
|
+
code,
|
|
301
|
+
regexErrorMessage,
|
|
302
|
+
"https://vercel.link/invalid-route-source-pattern",
|
|
303
|
+
"Learn More"
|
|
304
|
+
)
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const patternError = headers.map((r, i) => checkPatternSyntax("Header", i, r)).find(notEmpty);
|
|
308
|
+
if (patternError) {
|
|
309
|
+
return {
|
|
310
|
+
routes,
|
|
311
|
+
error: createError(
|
|
312
|
+
code,
|
|
313
|
+
patternError.message,
|
|
314
|
+
patternError.link,
|
|
315
|
+
"Learn More"
|
|
316
|
+
)
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
const normalized = normalizeRoutes((0, import_superstatic.convertHeaders)(headers));
|
|
320
|
+
if (normalized.error) {
|
|
321
|
+
normalized.error.code = code;
|
|
322
|
+
return { routes, error: normalized.error };
|
|
323
|
+
}
|
|
324
|
+
routes = routes || [];
|
|
325
|
+
routes.push(...normalized.routes || []);
|
|
326
|
+
}
|
|
327
|
+
if (typeof rewrites !== "undefined") {
|
|
328
|
+
const code = "invalid_rewrite";
|
|
329
|
+
const regexErrorMessage = rewrites.map((r, i) => checkRegexSyntax("Rewrite", i, r.source)).find(notEmpty);
|
|
330
|
+
if (regexErrorMessage) {
|
|
331
|
+
return {
|
|
332
|
+
routes,
|
|
333
|
+
error: createError(
|
|
334
|
+
code,
|
|
335
|
+
regexErrorMessage,
|
|
336
|
+
"https://vercel.link/invalid-route-source-pattern",
|
|
337
|
+
"Learn More"
|
|
338
|
+
)
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
const patternError = rewrites.map((r, i) => checkPatternSyntax("Rewrite", i, r)).find(notEmpty);
|
|
342
|
+
if (patternError) {
|
|
343
|
+
return {
|
|
344
|
+
routes,
|
|
345
|
+
error: createError(
|
|
346
|
+
code,
|
|
347
|
+
patternError.message,
|
|
348
|
+
patternError.link,
|
|
349
|
+
"Learn More"
|
|
350
|
+
)
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const normalized = normalizeRoutes((0, import_superstatic.convertRewrites)(rewrites));
|
|
354
|
+
if (normalized.error) {
|
|
355
|
+
normalized.error.code = code;
|
|
356
|
+
return { routes, error: normalized.error };
|
|
315
357
|
}
|
|
316
|
-
|
|
358
|
+
routes = routes || [];
|
|
359
|
+
routes.push({ handle: "filesystem" });
|
|
360
|
+
routes.push(...normalized.routes || []);
|
|
361
|
+
}
|
|
362
|
+
return { routes, error: null };
|
|
317
363
|
}
|
|
318
|
-
|
|
364
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
365
|
+
0 && (module.exports = {
|
|
366
|
+
appendRoutesToPhase,
|
|
367
|
+
getCleanUrls,
|
|
368
|
+
getTransformedRoutes,
|
|
369
|
+
isHandler,
|
|
370
|
+
isValidHandleValue,
|
|
371
|
+
mergeRoutes,
|
|
372
|
+
normalizeRoutes,
|
|
373
|
+
...require("./schemas"),
|
|
374
|
+
...require("./types")
|
|
375
|
+
});
|