@webtypen/webframez-react 0.0.27 → 0.0.29
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/README.md +4 -4
- package/dist/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/dist/http.cjs +91 -20
- package/dist/http.js +91 -20
- package/dist/index.cjs +91 -20
- package/dist/index.js +91 -20
- package/dist/router.cjs +22 -16
- package/dist/router.js +22 -16
- package/dist/types.d.ts +10 -1
- package/dist/webframez-core.cjs +91 -20
- package/dist/webframez-core.js +91 -20
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -185,7 +185,7 @@ var import_node_path2 = __toESM(require("node:path"), 1);
|
|
|
185
185
|
|
|
186
186
|
// src/head.ts
|
|
187
187
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
188
|
-
function
|
|
188
|
+
function normalizeHeadBasename(value) {
|
|
189
189
|
const trimmed = value?.trim();
|
|
190
190
|
if (!trimmed) {
|
|
191
191
|
return void 0;
|
|
@@ -195,45 +195,45 @@ function normalizeAssetsBaseUrl(value) {
|
|
|
195
195
|
}
|
|
196
196
|
return trimmed.replace(/\/+$/, "");
|
|
197
197
|
}
|
|
198
|
-
function resolveHeadAssetUrl(assetUrl,
|
|
198
|
+
function resolveHeadAssetUrl(assetUrl, basename) {
|
|
199
199
|
const normalizedAssetUrl = assetUrl.trim();
|
|
200
|
-
const
|
|
201
|
-
if (!normalizedAssetUrl || !
|
|
200
|
+
const normalizedBasename = normalizeHeadBasename(basename);
|
|
201
|
+
if (!normalizedAssetUrl || !normalizedBasename) {
|
|
202
202
|
return normalizedAssetUrl;
|
|
203
203
|
}
|
|
204
204
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
205
205
|
return normalizedAssetUrl;
|
|
206
206
|
}
|
|
207
|
-
if (
|
|
207
|
+
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
208
208
|
return normalizedAssetUrl;
|
|
209
209
|
}
|
|
210
|
-
if (
|
|
210
|
+
if (normalizedBasename === "/") {
|
|
211
211
|
return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
|
|
212
212
|
}
|
|
213
213
|
if (normalizedAssetUrl.startsWith("/")) {
|
|
214
|
-
return `${
|
|
214
|
+
return `${normalizedBasename}${normalizedAssetUrl}`;
|
|
215
215
|
}
|
|
216
|
-
return `${
|
|
216
|
+
return `${normalizedBasename}/${normalizedAssetUrl}`;
|
|
217
217
|
}
|
|
218
|
-
function normalizeHeadConfig(head,
|
|
218
|
+
function normalizeHeadConfig(head, inheritedBasename) {
|
|
219
219
|
if (!head) {
|
|
220
220
|
return void 0;
|
|
221
221
|
}
|
|
222
|
-
const
|
|
222
|
+
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
223
223
|
const normalizedHead = {
|
|
224
224
|
...head,
|
|
225
|
-
...
|
|
225
|
+
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
226
226
|
};
|
|
227
227
|
if (normalizedHead.favicon) {
|
|
228
228
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
229
229
|
normalizedHead.favicon,
|
|
230
|
-
|
|
230
|
+
effectiveBasename
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
233
|
if (normalizedHead.links) {
|
|
234
234
|
normalizedHead.links = normalizedHead.links.map((link) => ({
|
|
235
235
|
...link,
|
|
236
|
-
href: resolveHeadAssetUrl(link.href,
|
|
236
|
+
href: resolveHeadAssetUrl(link.href, effectiveBasename)
|
|
237
237
|
}));
|
|
238
238
|
}
|
|
239
239
|
return normalizedHead;
|
|
@@ -455,7 +455,7 @@ function mergeHead(...configs) {
|
|
|
455
455
|
links: []
|
|
456
456
|
};
|
|
457
457
|
for (const candidate of configs) {
|
|
458
|
-
const config = normalizeHeadConfig(candidate, merged.
|
|
458
|
+
const config = normalizeHeadConfig(candidate, merged.basename);
|
|
459
459
|
if (!config) {
|
|
460
460
|
continue;
|
|
461
461
|
}
|
|
@@ -465,8 +465,8 @@ function mergeHead(...configs) {
|
|
|
465
465
|
if (config.description) {
|
|
466
466
|
merged.description = config.description;
|
|
467
467
|
}
|
|
468
|
-
if (config.
|
|
469
|
-
merged.
|
|
468
|
+
if (config.basename) {
|
|
469
|
+
merged.basename = config.basename;
|
|
470
470
|
}
|
|
471
471
|
if (config.favicon) {
|
|
472
472
|
merged.favicon = config.favicon;
|
|
@@ -713,6 +713,12 @@ function createFileRouter(options) {
|
|
|
713
713
|
params: {},
|
|
714
714
|
searchParams: input.searchParams,
|
|
715
715
|
cookies: input.cookies ?? {},
|
|
716
|
+
request: input.request ?? {
|
|
717
|
+
host: null,
|
|
718
|
+
pathname,
|
|
719
|
+
originalPathname: pathname,
|
|
720
|
+
headers: {}
|
|
721
|
+
},
|
|
716
722
|
abort: (options2) => {
|
|
717
723
|
throw createAbort(options2);
|
|
718
724
|
}
|
|
@@ -944,6 +950,60 @@ function normalizeBasePath(basePath) {
|
|
|
944
950
|
const withLeadingSlash = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
945
951
|
return withLeadingSlash.endsWith("/") ? withLeadingSlash.slice(0, -1) : withLeadingSlash;
|
|
946
952
|
}
|
|
953
|
+
function normalizeRequestHostValue(value) {
|
|
954
|
+
const trimmed = value.trim();
|
|
955
|
+
if (!trimmed) {
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
const firstValue = trimmed.split(",")[0]?.trim() || "";
|
|
959
|
+
if (!firstValue) {
|
|
960
|
+
return null;
|
|
961
|
+
}
|
|
962
|
+
if (firstValue.startsWith("[")) {
|
|
963
|
+
const closingIndex = firstValue.indexOf("]");
|
|
964
|
+
if (closingIndex > 0) {
|
|
965
|
+
return firstValue.slice(1, closingIndex).toLowerCase();
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return firstValue.replace(/:\d+$/, "").toLowerCase();
|
|
969
|
+
}
|
|
970
|
+
function getRequestHost(req) {
|
|
971
|
+
const candidates = [
|
|
972
|
+
req.headers["x-forwarded-host"],
|
|
973
|
+
req.headers["x-original-host"],
|
|
974
|
+
req.headers.host
|
|
975
|
+
];
|
|
976
|
+
for (const candidate of candidates) {
|
|
977
|
+
if (Array.isArray(candidate)) {
|
|
978
|
+
for (const singleValue of candidate) {
|
|
979
|
+
if (typeof singleValue !== "string") {
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
const normalized2 = normalizeRequestHostValue(singleValue);
|
|
983
|
+
if (normalized2) {
|
|
984
|
+
return normalized2;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
if (typeof candidate !== "string") {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
const normalized = normalizeRequestHostValue(candidate);
|
|
993
|
+
if (normalized) {
|
|
994
|
+
return normalized;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
function createRouteRequestContext(req, pathname, originalPathname) {
|
|
1000
|
+
return {
|
|
1001
|
+
host: getRequestHost(req),
|
|
1002
|
+
pathname,
|
|
1003
|
+
originalPathname,
|
|
1004
|
+
headers: req.headers
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
947
1007
|
function stripBasePath(pathname, basePath) {
|
|
948
1008
|
if (!basePath) {
|
|
949
1009
|
return pathname;
|
|
@@ -1289,13 +1349,19 @@ function createNodeRequestHandler(options) {
|
|
|
1289
1349
|
}
|
|
1290
1350
|
if (url.pathname === rscPath) {
|
|
1291
1351
|
const pathname = stripBasePath(url.searchParams.get("path") || "/", basePath);
|
|
1352
|
+
const requestContext = createRouteRequestContext(
|
|
1353
|
+
req,
|
|
1354
|
+
pathname,
|
|
1355
|
+
url.searchParams.get("path") || "/"
|
|
1356
|
+
);
|
|
1292
1357
|
const search = new URLSearchParams(url.searchParams.get("search") || "");
|
|
1293
1358
|
const resolved2 = await withRequestBasename(
|
|
1294
1359
|
basePath,
|
|
1295
1360
|
() => router.resolve({
|
|
1296
1361
|
pathname,
|
|
1297
1362
|
searchParams: parseSearchParams(search),
|
|
1298
|
-
cookies: requestCookies
|
|
1363
|
+
cookies: requestCookies,
|
|
1364
|
+
request: requestContext
|
|
1299
1365
|
})
|
|
1300
1366
|
);
|
|
1301
1367
|
const payload = {
|
|
@@ -1335,7 +1401,12 @@ function createNodeRequestHandler(options) {
|
|
|
1335
1401
|
() => router.resolve({
|
|
1336
1402
|
pathname: stripBasePath(url.pathname, basePath),
|
|
1337
1403
|
searchParams: parseSearchParams(url.searchParams),
|
|
1338
|
-
cookies: requestCookies
|
|
1404
|
+
cookies: requestCookies,
|
|
1405
|
+
request: createRouteRequestContext(
|
|
1406
|
+
req,
|
|
1407
|
+
stripBasePath(url.pathname, basePath),
|
|
1408
|
+
url.pathname
|
|
1409
|
+
)
|
|
1339
1410
|
})
|
|
1340
1411
|
);
|
|
1341
1412
|
const initialPayload = {
|
|
@@ -1379,7 +1450,7 @@ function createNodeRequestHandler(options) {
|
|
|
1379
1450
|
rscEndpoint: rscPath,
|
|
1380
1451
|
rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
|
|
1381
1452
|
initialFlightData,
|
|
1382
|
-
basename: basePath,
|
|
1453
|
+
basename: resolved?.head?.basename ?? basePath,
|
|
1383
1454
|
liveReloadPath: liveReloadPath || void 0,
|
|
1384
1455
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1385
1456
|
})
|
|
@@ -1398,7 +1469,7 @@ function createNodeRequestHandler(options) {
|
|
|
1398
1469
|
rscEndpoint: rscPath,
|
|
1399
1470
|
rootHtml,
|
|
1400
1471
|
initialFlightData,
|
|
1401
|
-
basename: basePath,
|
|
1472
|
+
basename: resolved.head.basename ?? basePath,
|
|
1402
1473
|
liveReloadPath: liveReloadPath || void 0,
|
|
1403
1474
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1404
1475
|
})
|
package/dist/index.js
CHANGED
|
@@ -149,7 +149,7 @@ import path2 from "node:path";
|
|
|
149
149
|
|
|
150
150
|
// src/head.ts
|
|
151
151
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
152
|
-
function
|
|
152
|
+
function normalizeHeadBasename(value) {
|
|
153
153
|
const trimmed = value?.trim();
|
|
154
154
|
if (!trimmed) {
|
|
155
155
|
return void 0;
|
|
@@ -159,45 +159,45 @@ function normalizeAssetsBaseUrl(value) {
|
|
|
159
159
|
}
|
|
160
160
|
return trimmed.replace(/\/+$/, "");
|
|
161
161
|
}
|
|
162
|
-
function resolveHeadAssetUrl(assetUrl,
|
|
162
|
+
function resolveHeadAssetUrl(assetUrl, basename) {
|
|
163
163
|
const normalizedAssetUrl = assetUrl.trim();
|
|
164
|
-
const
|
|
165
|
-
if (!normalizedAssetUrl || !
|
|
164
|
+
const normalizedBasename = normalizeHeadBasename(basename);
|
|
165
|
+
if (!normalizedAssetUrl || !normalizedBasename) {
|
|
166
166
|
return normalizedAssetUrl;
|
|
167
167
|
}
|
|
168
168
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
169
169
|
return normalizedAssetUrl;
|
|
170
170
|
}
|
|
171
|
-
if (
|
|
171
|
+
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
172
172
|
return normalizedAssetUrl;
|
|
173
173
|
}
|
|
174
|
-
if (
|
|
174
|
+
if (normalizedBasename === "/") {
|
|
175
175
|
return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
|
|
176
176
|
}
|
|
177
177
|
if (normalizedAssetUrl.startsWith("/")) {
|
|
178
|
-
return `${
|
|
178
|
+
return `${normalizedBasename}${normalizedAssetUrl}`;
|
|
179
179
|
}
|
|
180
|
-
return `${
|
|
180
|
+
return `${normalizedBasename}/${normalizedAssetUrl}`;
|
|
181
181
|
}
|
|
182
|
-
function normalizeHeadConfig(head,
|
|
182
|
+
function normalizeHeadConfig(head, inheritedBasename) {
|
|
183
183
|
if (!head) {
|
|
184
184
|
return void 0;
|
|
185
185
|
}
|
|
186
|
-
const
|
|
186
|
+
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
187
187
|
const normalizedHead = {
|
|
188
188
|
...head,
|
|
189
|
-
...
|
|
189
|
+
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
190
190
|
};
|
|
191
191
|
if (normalizedHead.favicon) {
|
|
192
192
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
193
193
|
normalizedHead.favicon,
|
|
194
|
-
|
|
194
|
+
effectiveBasename
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
197
|
if (normalizedHead.links) {
|
|
198
198
|
normalizedHead.links = normalizedHead.links.map((link) => ({
|
|
199
199
|
...link,
|
|
200
|
-
href: resolveHeadAssetUrl(link.href,
|
|
200
|
+
href: resolveHeadAssetUrl(link.href, effectiveBasename)
|
|
201
201
|
}));
|
|
202
202
|
}
|
|
203
203
|
return normalizedHead;
|
|
@@ -419,7 +419,7 @@ function mergeHead(...configs) {
|
|
|
419
419
|
links: []
|
|
420
420
|
};
|
|
421
421
|
for (const candidate of configs) {
|
|
422
|
-
const config = normalizeHeadConfig(candidate, merged.
|
|
422
|
+
const config = normalizeHeadConfig(candidate, merged.basename);
|
|
423
423
|
if (!config) {
|
|
424
424
|
continue;
|
|
425
425
|
}
|
|
@@ -429,8 +429,8 @@ function mergeHead(...configs) {
|
|
|
429
429
|
if (config.description) {
|
|
430
430
|
merged.description = config.description;
|
|
431
431
|
}
|
|
432
|
-
if (config.
|
|
433
|
-
merged.
|
|
432
|
+
if (config.basename) {
|
|
433
|
+
merged.basename = config.basename;
|
|
434
434
|
}
|
|
435
435
|
if (config.favicon) {
|
|
436
436
|
merged.favicon = config.favicon;
|
|
@@ -677,6 +677,12 @@ function createFileRouter(options) {
|
|
|
677
677
|
params: {},
|
|
678
678
|
searchParams: input.searchParams,
|
|
679
679
|
cookies: input.cookies ?? {},
|
|
680
|
+
request: input.request ?? {
|
|
681
|
+
host: null,
|
|
682
|
+
pathname,
|
|
683
|
+
originalPathname: pathname,
|
|
684
|
+
headers: {}
|
|
685
|
+
},
|
|
680
686
|
abort: (options2) => {
|
|
681
687
|
throw createAbort(options2);
|
|
682
688
|
}
|
|
@@ -908,6 +914,60 @@ function normalizeBasePath(basePath) {
|
|
|
908
914
|
const withLeadingSlash = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
909
915
|
return withLeadingSlash.endsWith("/") ? withLeadingSlash.slice(0, -1) : withLeadingSlash;
|
|
910
916
|
}
|
|
917
|
+
function normalizeRequestHostValue(value) {
|
|
918
|
+
const trimmed = value.trim();
|
|
919
|
+
if (!trimmed) {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
const firstValue = trimmed.split(",")[0]?.trim() || "";
|
|
923
|
+
if (!firstValue) {
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
if (firstValue.startsWith("[")) {
|
|
927
|
+
const closingIndex = firstValue.indexOf("]");
|
|
928
|
+
if (closingIndex > 0) {
|
|
929
|
+
return firstValue.slice(1, closingIndex).toLowerCase();
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return firstValue.replace(/:\d+$/, "").toLowerCase();
|
|
933
|
+
}
|
|
934
|
+
function getRequestHost(req) {
|
|
935
|
+
const candidates = [
|
|
936
|
+
req.headers["x-forwarded-host"],
|
|
937
|
+
req.headers["x-original-host"],
|
|
938
|
+
req.headers.host
|
|
939
|
+
];
|
|
940
|
+
for (const candidate of candidates) {
|
|
941
|
+
if (Array.isArray(candidate)) {
|
|
942
|
+
for (const singleValue of candidate) {
|
|
943
|
+
if (typeof singleValue !== "string") {
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
const normalized2 = normalizeRequestHostValue(singleValue);
|
|
947
|
+
if (normalized2) {
|
|
948
|
+
return normalized2;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (typeof candidate !== "string") {
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
const normalized = normalizeRequestHostValue(candidate);
|
|
957
|
+
if (normalized) {
|
|
958
|
+
return normalized;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
function createRouteRequestContext(req, pathname, originalPathname) {
|
|
964
|
+
return {
|
|
965
|
+
host: getRequestHost(req),
|
|
966
|
+
pathname,
|
|
967
|
+
originalPathname,
|
|
968
|
+
headers: req.headers
|
|
969
|
+
};
|
|
970
|
+
}
|
|
911
971
|
function stripBasePath(pathname, basePath) {
|
|
912
972
|
if (!basePath) {
|
|
913
973
|
return pathname;
|
|
@@ -1253,13 +1313,19 @@ function createNodeRequestHandler(options) {
|
|
|
1253
1313
|
}
|
|
1254
1314
|
if (url.pathname === rscPath) {
|
|
1255
1315
|
const pathname = stripBasePath(url.searchParams.get("path") || "/", basePath);
|
|
1316
|
+
const requestContext = createRouteRequestContext(
|
|
1317
|
+
req,
|
|
1318
|
+
pathname,
|
|
1319
|
+
url.searchParams.get("path") || "/"
|
|
1320
|
+
);
|
|
1256
1321
|
const search = new URLSearchParams(url.searchParams.get("search") || "");
|
|
1257
1322
|
const resolved2 = await withRequestBasename(
|
|
1258
1323
|
basePath,
|
|
1259
1324
|
() => router.resolve({
|
|
1260
1325
|
pathname,
|
|
1261
1326
|
searchParams: parseSearchParams(search),
|
|
1262
|
-
cookies: requestCookies
|
|
1327
|
+
cookies: requestCookies,
|
|
1328
|
+
request: requestContext
|
|
1263
1329
|
})
|
|
1264
1330
|
);
|
|
1265
1331
|
const payload = {
|
|
@@ -1299,7 +1365,12 @@ function createNodeRequestHandler(options) {
|
|
|
1299
1365
|
() => router.resolve({
|
|
1300
1366
|
pathname: stripBasePath(url.pathname, basePath),
|
|
1301
1367
|
searchParams: parseSearchParams(url.searchParams),
|
|
1302
|
-
cookies: requestCookies
|
|
1368
|
+
cookies: requestCookies,
|
|
1369
|
+
request: createRouteRequestContext(
|
|
1370
|
+
req,
|
|
1371
|
+
stripBasePath(url.pathname, basePath),
|
|
1372
|
+
url.pathname
|
|
1373
|
+
)
|
|
1303
1374
|
})
|
|
1304
1375
|
);
|
|
1305
1376
|
const initialPayload = {
|
|
@@ -1343,7 +1414,7 @@ function createNodeRequestHandler(options) {
|
|
|
1343
1414
|
rscEndpoint: rscPath,
|
|
1344
1415
|
rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
|
|
1345
1416
|
initialFlightData,
|
|
1346
|
-
basename: basePath,
|
|
1417
|
+
basename: resolved?.head?.basename ?? basePath,
|
|
1347
1418
|
liveReloadPath: liveReloadPath || void 0,
|
|
1348
1419
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1349
1420
|
})
|
|
@@ -1362,7 +1433,7 @@ function createNodeRequestHandler(options) {
|
|
|
1362
1433
|
rscEndpoint: rscPath,
|
|
1363
1434
|
rootHtml,
|
|
1364
1435
|
initialFlightData,
|
|
1365
|
-
basename: basePath,
|
|
1436
|
+
basename: resolved.head.basename ?? basePath,
|
|
1366
1437
|
liveReloadPath: liveReloadPath || void 0,
|
|
1367
1438
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1368
1439
|
})
|
package/dist/router.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
43
43
|
|
|
44
44
|
// src/head.ts
|
|
45
45
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
46
|
-
function
|
|
46
|
+
function normalizeHeadBasename(value) {
|
|
47
47
|
const trimmed = value?.trim();
|
|
48
48
|
if (!trimmed) {
|
|
49
49
|
return void 0;
|
|
@@ -53,45 +53,45 @@ function normalizeAssetsBaseUrl(value) {
|
|
|
53
53
|
}
|
|
54
54
|
return trimmed.replace(/\/+$/, "");
|
|
55
55
|
}
|
|
56
|
-
function resolveHeadAssetUrl(assetUrl,
|
|
56
|
+
function resolveHeadAssetUrl(assetUrl, basename) {
|
|
57
57
|
const normalizedAssetUrl = assetUrl.trim();
|
|
58
|
-
const
|
|
59
|
-
if (!normalizedAssetUrl || !
|
|
58
|
+
const normalizedBasename = normalizeHeadBasename(basename);
|
|
59
|
+
if (!normalizedAssetUrl || !normalizedBasename) {
|
|
60
60
|
return normalizedAssetUrl;
|
|
61
61
|
}
|
|
62
62
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
63
63
|
return normalizedAssetUrl;
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
65
|
+
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
66
66
|
return normalizedAssetUrl;
|
|
67
67
|
}
|
|
68
|
-
if (
|
|
68
|
+
if (normalizedBasename === "/") {
|
|
69
69
|
return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
|
|
70
70
|
}
|
|
71
71
|
if (normalizedAssetUrl.startsWith("/")) {
|
|
72
|
-
return `${
|
|
72
|
+
return `${normalizedBasename}${normalizedAssetUrl}`;
|
|
73
73
|
}
|
|
74
|
-
return `${
|
|
74
|
+
return `${normalizedBasename}/${normalizedAssetUrl}`;
|
|
75
75
|
}
|
|
76
|
-
function normalizeHeadConfig(head,
|
|
76
|
+
function normalizeHeadConfig(head, inheritedBasename) {
|
|
77
77
|
if (!head) {
|
|
78
78
|
return void 0;
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
81
81
|
const normalizedHead = {
|
|
82
82
|
...head,
|
|
83
|
-
...
|
|
83
|
+
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
84
84
|
};
|
|
85
85
|
if (normalizedHead.favicon) {
|
|
86
86
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
87
87
|
normalizedHead.favicon,
|
|
88
|
-
|
|
88
|
+
effectiveBasename
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
if (normalizedHead.links) {
|
|
92
92
|
normalizedHead.links = normalizedHead.links.map((link) => ({
|
|
93
93
|
...link,
|
|
94
|
-
href: resolveHeadAssetUrl(link.href,
|
|
94
|
+
href: resolveHeadAssetUrl(link.href, effectiveBasename)
|
|
95
95
|
}));
|
|
96
96
|
}
|
|
97
97
|
return normalizedHead;
|
|
@@ -313,7 +313,7 @@ function mergeHead(...configs) {
|
|
|
313
313
|
links: []
|
|
314
314
|
};
|
|
315
315
|
for (const candidate of configs) {
|
|
316
|
-
const config = normalizeHeadConfig(candidate, merged.
|
|
316
|
+
const config = normalizeHeadConfig(candidate, merged.basename);
|
|
317
317
|
if (!config) {
|
|
318
318
|
continue;
|
|
319
319
|
}
|
|
@@ -323,8 +323,8 @@ function mergeHead(...configs) {
|
|
|
323
323
|
if (config.description) {
|
|
324
324
|
merged.description = config.description;
|
|
325
325
|
}
|
|
326
|
-
if (config.
|
|
327
|
-
merged.
|
|
326
|
+
if (config.basename) {
|
|
327
|
+
merged.basename = config.basename;
|
|
328
328
|
}
|
|
329
329
|
if (config.favicon) {
|
|
330
330
|
merged.favicon = config.favicon;
|
|
@@ -571,6 +571,12 @@ function createFileRouter(options) {
|
|
|
571
571
|
params: {},
|
|
572
572
|
searchParams: input.searchParams,
|
|
573
573
|
cookies: input.cookies ?? {},
|
|
574
|
+
request: input.request ?? {
|
|
575
|
+
host: null,
|
|
576
|
+
pathname,
|
|
577
|
+
originalPathname: pathname,
|
|
578
|
+
headers: {}
|
|
579
|
+
},
|
|
574
580
|
abort: (options2) => {
|
|
575
581
|
throw createAbort(options2);
|
|
576
582
|
}
|
package/dist/router.js
CHANGED
|
@@ -13,7 +13,7 @@ import path from "node:path";
|
|
|
13
13
|
|
|
14
14
|
// src/head.ts
|
|
15
15
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
16
|
-
function
|
|
16
|
+
function normalizeHeadBasename(value) {
|
|
17
17
|
const trimmed = value?.trim();
|
|
18
18
|
if (!trimmed) {
|
|
19
19
|
return void 0;
|
|
@@ -23,45 +23,45 @@ function normalizeAssetsBaseUrl(value) {
|
|
|
23
23
|
}
|
|
24
24
|
return trimmed.replace(/\/+$/, "");
|
|
25
25
|
}
|
|
26
|
-
function resolveHeadAssetUrl(assetUrl,
|
|
26
|
+
function resolveHeadAssetUrl(assetUrl, basename) {
|
|
27
27
|
const normalizedAssetUrl = assetUrl.trim();
|
|
28
|
-
const
|
|
29
|
-
if (!normalizedAssetUrl || !
|
|
28
|
+
const normalizedBasename = normalizeHeadBasename(basename);
|
|
29
|
+
if (!normalizedAssetUrl || !normalizedBasename) {
|
|
30
30
|
return normalizedAssetUrl;
|
|
31
31
|
}
|
|
32
32
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
33
33
|
return normalizedAssetUrl;
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
36
36
|
return normalizedAssetUrl;
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
38
|
+
if (normalizedBasename === "/") {
|
|
39
39
|
return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
|
|
40
40
|
}
|
|
41
41
|
if (normalizedAssetUrl.startsWith("/")) {
|
|
42
|
-
return `${
|
|
42
|
+
return `${normalizedBasename}${normalizedAssetUrl}`;
|
|
43
43
|
}
|
|
44
|
-
return `${
|
|
44
|
+
return `${normalizedBasename}/${normalizedAssetUrl}`;
|
|
45
45
|
}
|
|
46
|
-
function normalizeHeadConfig(head,
|
|
46
|
+
function normalizeHeadConfig(head, inheritedBasename) {
|
|
47
47
|
if (!head) {
|
|
48
48
|
return void 0;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
50
|
+
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
51
51
|
const normalizedHead = {
|
|
52
52
|
...head,
|
|
53
|
-
...
|
|
53
|
+
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
54
54
|
};
|
|
55
55
|
if (normalizedHead.favicon) {
|
|
56
56
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
57
57
|
normalizedHead.favicon,
|
|
58
|
-
|
|
58
|
+
effectiveBasename
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
if (normalizedHead.links) {
|
|
62
62
|
normalizedHead.links = normalizedHead.links.map((link) => ({
|
|
63
63
|
...link,
|
|
64
|
-
href: resolveHeadAssetUrl(link.href,
|
|
64
|
+
href: resolveHeadAssetUrl(link.href, effectiveBasename)
|
|
65
65
|
}));
|
|
66
66
|
}
|
|
67
67
|
return normalizedHead;
|
|
@@ -283,7 +283,7 @@ function mergeHead(...configs) {
|
|
|
283
283
|
links: []
|
|
284
284
|
};
|
|
285
285
|
for (const candidate of configs) {
|
|
286
|
-
const config = normalizeHeadConfig(candidate, merged.
|
|
286
|
+
const config = normalizeHeadConfig(candidate, merged.basename);
|
|
287
287
|
if (!config) {
|
|
288
288
|
continue;
|
|
289
289
|
}
|
|
@@ -293,8 +293,8 @@ function mergeHead(...configs) {
|
|
|
293
293
|
if (config.description) {
|
|
294
294
|
merged.description = config.description;
|
|
295
295
|
}
|
|
296
|
-
if (config.
|
|
297
|
-
merged.
|
|
296
|
+
if (config.basename) {
|
|
297
|
+
merged.basename = config.basename;
|
|
298
298
|
}
|
|
299
299
|
if (config.favicon) {
|
|
300
300
|
merged.favicon = config.favicon;
|
|
@@ -541,6 +541,12 @@ function createFileRouter(options) {
|
|
|
541
541
|
params: {},
|
|
542
542
|
searchParams: input.searchParams,
|
|
543
543
|
cookies: input.cookies ?? {},
|
|
544
|
+
request: input.request ?? {
|
|
545
|
+
host: null,
|
|
546
|
+
pathname,
|
|
547
|
+
originalPathname: pathname,
|
|
548
|
+
headers: {}
|
|
549
|
+
},
|
|
544
550
|
abort: (options2) => {
|
|
545
551
|
throw createAbort(options2);
|
|
546
552
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,14 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
|
|
3
3
|
export type RouteParams = Record<string, string | string[]>;
|
|
4
4
|
export type RouteSearchParams = Record<string, string | string[]>;
|
|
5
|
+
export type RouteRequestHeaders = Record<string, string | string[] | undefined>;
|
|
6
|
+
|
|
7
|
+
export type RouteRequestContext = {
|
|
8
|
+
host: string | null;
|
|
9
|
+
pathname: string;
|
|
10
|
+
originalPathname: string;
|
|
11
|
+
headers: RouteRequestHeaders;
|
|
12
|
+
};
|
|
5
13
|
|
|
6
14
|
export type AbortRouteOptions = {
|
|
7
15
|
status?: number;
|
|
@@ -14,6 +22,7 @@ export type RouteContext<TData = any> = {
|
|
|
14
22
|
params: RouteParams;
|
|
15
23
|
searchParams: RouteSearchParams;
|
|
16
24
|
cookies: Record<string, string>;
|
|
25
|
+
request: RouteRequestContext;
|
|
17
26
|
data?: TData;
|
|
18
27
|
abort: (options?: AbortRouteOptions) => never;
|
|
19
28
|
};
|
|
@@ -51,7 +60,7 @@ export type HeadLinkTag = {
|
|
|
51
60
|
export type HeadConfig = {
|
|
52
61
|
title?: string;
|
|
53
62
|
description?: string;
|
|
54
|
-
|
|
63
|
+
basename?: string;
|
|
55
64
|
favicon?: string;
|
|
56
65
|
meta?: HeadMetaTag[];
|
|
57
66
|
links?: HeadLinkTag[];
|