@webtypen/webframez-react 0.0.27 → 0.0.28

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.
@@ -155,7 +155,7 @@ var import_node_path2 = __toESM(require("node:path"), 1);
155
155
 
156
156
  // src/head.ts
157
157
  var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
158
- function normalizeAssetsBaseUrl(value) {
158
+ function normalizeHeadBasename(value) {
159
159
  const trimmed = value?.trim();
160
160
  if (!trimmed) {
161
161
  return void 0;
@@ -165,45 +165,45 @@ function normalizeAssetsBaseUrl(value) {
165
165
  }
166
166
  return trimmed.replace(/\/+$/, "");
167
167
  }
168
- function resolveHeadAssetUrl(assetUrl, assetsBaseUrl) {
168
+ function resolveHeadAssetUrl(assetUrl, basename) {
169
169
  const normalizedAssetUrl = assetUrl.trim();
170
- const normalizedAssetsBaseUrl = normalizeAssetsBaseUrl(assetsBaseUrl);
171
- if (!normalizedAssetUrl || !normalizedAssetsBaseUrl) {
170
+ const normalizedBasename = normalizeHeadBasename(basename);
171
+ if (!normalizedAssetUrl || !normalizedBasename) {
172
172
  return normalizedAssetUrl;
173
173
  }
174
174
  if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
175
175
  return normalizedAssetUrl;
176
176
  }
177
- if (normalizedAssetsBaseUrl !== "/" && (normalizedAssetUrl === normalizedAssetsBaseUrl || normalizedAssetUrl.startsWith(`${normalizedAssetsBaseUrl}/`))) {
177
+ if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
178
178
  return normalizedAssetUrl;
179
179
  }
180
- if (normalizedAssetsBaseUrl === "/") {
180
+ if (normalizedBasename === "/") {
181
181
  return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
182
182
  }
183
183
  if (normalizedAssetUrl.startsWith("/")) {
184
- return `${normalizedAssetsBaseUrl}${normalizedAssetUrl}`;
184
+ return `${normalizedBasename}${normalizedAssetUrl}`;
185
185
  }
186
- return `${normalizedAssetsBaseUrl}/${normalizedAssetUrl}`;
186
+ return `${normalizedBasename}/${normalizedAssetUrl}`;
187
187
  }
188
- function normalizeHeadConfig(head, inheritedAssetsBaseUrl) {
188
+ function normalizeHeadConfig(head, inheritedBasename) {
189
189
  if (!head) {
190
190
  return void 0;
191
191
  }
192
- const effectiveAssetsBaseUrl = normalizeAssetsBaseUrl(head.assetsBaseUrl) ?? normalizeAssetsBaseUrl(inheritedAssetsBaseUrl);
192
+ const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
193
193
  const normalizedHead = {
194
194
  ...head,
195
- ...effectiveAssetsBaseUrl ? { assetsBaseUrl: effectiveAssetsBaseUrl } : {}
195
+ ...effectiveBasename ? { basename: effectiveBasename } : {}
196
196
  };
197
197
  if (normalizedHead.favicon) {
198
198
  normalizedHead.favicon = resolveHeadAssetUrl(
199
199
  normalizedHead.favicon,
200
- effectiveAssetsBaseUrl
200
+ effectiveBasename
201
201
  );
202
202
  }
203
203
  if (normalizedHead.links) {
204
204
  normalizedHead.links = normalizedHead.links.map((link) => ({
205
205
  ...link,
206
- href: resolveHeadAssetUrl(link.href, effectiveAssetsBaseUrl)
206
+ href: resolveHeadAssetUrl(link.href, effectiveBasename)
207
207
  }));
208
208
  }
209
209
  return normalizedHead;
@@ -425,7 +425,7 @@ function mergeHead(...configs) {
425
425
  links: []
426
426
  };
427
427
  for (const candidate of configs) {
428
- const config = normalizeHeadConfig(candidate, merged.assetsBaseUrl);
428
+ const config = normalizeHeadConfig(candidate, merged.basename);
429
429
  if (!config) {
430
430
  continue;
431
431
  }
@@ -435,8 +435,8 @@ function mergeHead(...configs) {
435
435
  if (config.description) {
436
436
  merged.description = config.description;
437
437
  }
438
- if (config.assetsBaseUrl) {
439
- merged.assetsBaseUrl = config.assetsBaseUrl;
438
+ if (config.basename) {
439
+ merged.basename = config.basename;
440
440
  }
441
441
  if (config.favicon) {
442
442
  merged.favicon = config.favicon;
@@ -683,6 +683,12 @@ function createFileRouter(options) {
683
683
  params: {},
684
684
  searchParams: input.searchParams,
685
685
  cookies: input.cookies ?? {},
686
+ request: input.request ?? {
687
+ host: null,
688
+ pathname,
689
+ originalPathname: pathname,
690
+ headers: {}
691
+ },
686
692
  abort: (options2) => {
687
693
  throw createAbort(options2);
688
694
  }
@@ -910,6 +916,60 @@ function normalizeBasePath(basePath) {
910
916
  const withLeadingSlash = basePath.startsWith("/") ? basePath : `/${basePath}`;
911
917
  return withLeadingSlash.endsWith("/") ? withLeadingSlash.slice(0, -1) : withLeadingSlash;
912
918
  }
919
+ function normalizeRequestHostValue(value) {
920
+ const trimmed = value.trim();
921
+ if (!trimmed) {
922
+ return null;
923
+ }
924
+ const firstValue = trimmed.split(",")[0]?.trim() || "";
925
+ if (!firstValue) {
926
+ return null;
927
+ }
928
+ if (firstValue.startsWith("[")) {
929
+ const closingIndex = firstValue.indexOf("]");
930
+ if (closingIndex > 0) {
931
+ return firstValue.slice(1, closingIndex).toLowerCase();
932
+ }
933
+ }
934
+ return firstValue.replace(/:\d+$/, "").toLowerCase();
935
+ }
936
+ function getRequestHost(req) {
937
+ const candidates = [
938
+ req.headers["x-forwarded-host"],
939
+ req.headers["x-original-host"],
940
+ req.headers.host
941
+ ];
942
+ for (const candidate of candidates) {
943
+ if (Array.isArray(candidate)) {
944
+ for (const singleValue of candidate) {
945
+ if (typeof singleValue !== "string") {
946
+ continue;
947
+ }
948
+ const normalized2 = normalizeRequestHostValue(singleValue);
949
+ if (normalized2) {
950
+ return normalized2;
951
+ }
952
+ }
953
+ continue;
954
+ }
955
+ if (typeof candidate !== "string") {
956
+ continue;
957
+ }
958
+ const normalized = normalizeRequestHostValue(candidate);
959
+ if (normalized) {
960
+ return normalized;
961
+ }
962
+ }
963
+ return null;
964
+ }
965
+ function createRouteRequestContext(req, pathname, originalPathname) {
966
+ return {
967
+ host: getRequestHost(req),
968
+ pathname,
969
+ originalPathname,
970
+ headers: req.headers
971
+ };
972
+ }
913
973
  function stripBasePath(pathname, basePath) {
914
974
  if (!basePath) {
915
975
  return pathname;
@@ -1255,13 +1315,19 @@ function createNodeRequestHandler(options) {
1255
1315
  }
1256
1316
  if (url.pathname === rscPath) {
1257
1317
  const pathname = stripBasePath(url.searchParams.get("path") || "/", basePath);
1318
+ const requestContext = createRouteRequestContext(
1319
+ req,
1320
+ pathname,
1321
+ url.searchParams.get("path") || "/"
1322
+ );
1258
1323
  const search = new URLSearchParams(url.searchParams.get("search") || "");
1259
1324
  const resolved2 = await withRequestBasename(
1260
1325
  basePath,
1261
1326
  () => router.resolve({
1262
1327
  pathname,
1263
1328
  searchParams: parseSearchParams(search),
1264
- cookies: requestCookies
1329
+ cookies: requestCookies,
1330
+ request: requestContext
1265
1331
  })
1266
1332
  );
1267
1333
  const payload = {
@@ -1301,7 +1367,12 @@ function createNodeRequestHandler(options) {
1301
1367
  () => router.resolve({
1302
1368
  pathname: stripBasePath(url.pathname, basePath),
1303
1369
  searchParams: parseSearchParams(url.searchParams),
1304
- cookies: requestCookies
1370
+ cookies: requestCookies,
1371
+ request: createRouteRequestContext(
1372
+ req,
1373
+ stripBasePath(url.pathname, basePath),
1374
+ url.pathname
1375
+ )
1305
1376
  })
1306
1377
  );
1307
1378
  const initialPayload = {
@@ -1345,7 +1416,7 @@ function createNodeRequestHandler(options) {
1345
1416
  rscEndpoint: rscPath,
1346
1417
  rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
1347
1418
  initialFlightData,
1348
- basename: basePath,
1419
+ basename: resolved?.head?.basename ?? basePath,
1349
1420
  liveReloadPath: liveReloadPath || void 0,
1350
1421
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1351
1422
  })
@@ -1364,7 +1435,7 @@ function createNodeRequestHandler(options) {
1364
1435
  rscEndpoint: rscPath,
1365
1436
  rootHtml,
1366
1437
  initialFlightData,
1367
- basename: basePath,
1438
+ basename: resolved.head.basename ?? basePath,
1368
1439
  liveReloadPath: liveReloadPath || void 0,
1369
1440
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1370
1441
  })
@@ -127,7 +127,7 @@ import path2 from "node:path";
127
127
 
128
128
  // src/head.ts
129
129
  var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
130
- function normalizeAssetsBaseUrl(value) {
130
+ function normalizeHeadBasename(value) {
131
131
  const trimmed = value?.trim();
132
132
  if (!trimmed) {
133
133
  return void 0;
@@ -137,45 +137,45 @@ function normalizeAssetsBaseUrl(value) {
137
137
  }
138
138
  return trimmed.replace(/\/+$/, "");
139
139
  }
140
- function resolveHeadAssetUrl(assetUrl, assetsBaseUrl) {
140
+ function resolveHeadAssetUrl(assetUrl, basename) {
141
141
  const normalizedAssetUrl = assetUrl.trim();
142
- const normalizedAssetsBaseUrl = normalizeAssetsBaseUrl(assetsBaseUrl);
143
- if (!normalizedAssetUrl || !normalizedAssetsBaseUrl) {
142
+ const normalizedBasename = normalizeHeadBasename(basename);
143
+ if (!normalizedAssetUrl || !normalizedBasename) {
144
144
  return normalizedAssetUrl;
145
145
  }
146
146
  if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
147
147
  return normalizedAssetUrl;
148
148
  }
149
- if (normalizedAssetsBaseUrl !== "/" && (normalizedAssetUrl === normalizedAssetsBaseUrl || normalizedAssetUrl.startsWith(`${normalizedAssetsBaseUrl}/`))) {
149
+ if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
150
150
  return normalizedAssetUrl;
151
151
  }
152
- if (normalizedAssetsBaseUrl === "/") {
152
+ if (normalizedBasename === "/") {
153
153
  return normalizedAssetUrl.startsWith("/") ? normalizedAssetUrl : `/${normalizedAssetUrl}`;
154
154
  }
155
155
  if (normalizedAssetUrl.startsWith("/")) {
156
- return `${normalizedAssetsBaseUrl}${normalizedAssetUrl}`;
156
+ return `${normalizedBasename}${normalizedAssetUrl}`;
157
157
  }
158
- return `${normalizedAssetsBaseUrl}/${normalizedAssetUrl}`;
158
+ return `${normalizedBasename}/${normalizedAssetUrl}`;
159
159
  }
160
- function normalizeHeadConfig(head, inheritedAssetsBaseUrl) {
160
+ function normalizeHeadConfig(head, inheritedBasename) {
161
161
  if (!head) {
162
162
  return void 0;
163
163
  }
164
- const effectiveAssetsBaseUrl = normalizeAssetsBaseUrl(head.assetsBaseUrl) ?? normalizeAssetsBaseUrl(inheritedAssetsBaseUrl);
164
+ const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
165
165
  const normalizedHead = {
166
166
  ...head,
167
- ...effectiveAssetsBaseUrl ? { assetsBaseUrl: effectiveAssetsBaseUrl } : {}
167
+ ...effectiveBasename ? { basename: effectiveBasename } : {}
168
168
  };
169
169
  if (normalizedHead.favicon) {
170
170
  normalizedHead.favicon = resolveHeadAssetUrl(
171
171
  normalizedHead.favicon,
172
- effectiveAssetsBaseUrl
172
+ effectiveBasename
173
173
  );
174
174
  }
175
175
  if (normalizedHead.links) {
176
176
  normalizedHead.links = normalizedHead.links.map((link) => ({
177
177
  ...link,
178
- href: resolveHeadAssetUrl(link.href, effectiveAssetsBaseUrl)
178
+ href: resolveHeadAssetUrl(link.href, effectiveBasename)
179
179
  }));
180
180
  }
181
181
  return normalizedHead;
@@ -397,7 +397,7 @@ function mergeHead(...configs) {
397
397
  links: []
398
398
  };
399
399
  for (const candidate of configs) {
400
- const config = normalizeHeadConfig(candidate, merged.assetsBaseUrl);
400
+ const config = normalizeHeadConfig(candidate, merged.basename);
401
401
  if (!config) {
402
402
  continue;
403
403
  }
@@ -407,8 +407,8 @@ function mergeHead(...configs) {
407
407
  if (config.description) {
408
408
  merged.description = config.description;
409
409
  }
410
- if (config.assetsBaseUrl) {
411
- merged.assetsBaseUrl = config.assetsBaseUrl;
410
+ if (config.basename) {
411
+ merged.basename = config.basename;
412
412
  }
413
413
  if (config.favicon) {
414
414
  merged.favicon = config.favicon;
@@ -655,6 +655,12 @@ function createFileRouter(options) {
655
655
  params: {},
656
656
  searchParams: input.searchParams,
657
657
  cookies: input.cookies ?? {},
658
+ request: input.request ?? {
659
+ host: null,
660
+ pathname,
661
+ originalPathname: pathname,
662
+ headers: {}
663
+ },
658
664
  abort: (options2) => {
659
665
  throw createAbort(options2);
660
666
  }
@@ -882,6 +888,60 @@ function normalizeBasePath(basePath) {
882
888
  const withLeadingSlash = basePath.startsWith("/") ? basePath : `/${basePath}`;
883
889
  return withLeadingSlash.endsWith("/") ? withLeadingSlash.slice(0, -1) : withLeadingSlash;
884
890
  }
891
+ function normalizeRequestHostValue(value) {
892
+ const trimmed = value.trim();
893
+ if (!trimmed) {
894
+ return null;
895
+ }
896
+ const firstValue = trimmed.split(",")[0]?.trim() || "";
897
+ if (!firstValue) {
898
+ return null;
899
+ }
900
+ if (firstValue.startsWith("[")) {
901
+ const closingIndex = firstValue.indexOf("]");
902
+ if (closingIndex > 0) {
903
+ return firstValue.slice(1, closingIndex).toLowerCase();
904
+ }
905
+ }
906
+ return firstValue.replace(/:\d+$/, "").toLowerCase();
907
+ }
908
+ function getRequestHost(req) {
909
+ const candidates = [
910
+ req.headers["x-forwarded-host"],
911
+ req.headers["x-original-host"],
912
+ req.headers.host
913
+ ];
914
+ for (const candidate of candidates) {
915
+ if (Array.isArray(candidate)) {
916
+ for (const singleValue of candidate) {
917
+ if (typeof singleValue !== "string") {
918
+ continue;
919
+ }
920
+ const normalized2 = normalizeRequestHostValue(singleValue);
921
+ if (normalized2) {
922
+ return normalized2;
923
+ }
924
+ }
925
+ continue;
926
+ }
927
+ if (typeof candidate !== "string") {
928
+ continue;
929
+ }
930
+ const normalized = normalizeRequestHostValue(candidate);
931
+ if (normalized) {
932
+ return normalized;
933
+ }
934
+ }
935
+ return null;
936
+ }
937
+ function createRouteRequestContext(req, pathname, originalPathname) {
938
+ return {
939
+ host: getRequestHost(req),
940
+ pathname,
941
+ originalPathname,
942
+ headers: req.headers
943
+ };
944
+ }
885
945
  function stripBasePath(pathname, basePath) {
886
946
  if (!basePath) {
887
947
  return pathname;
@@ -1227,13 +1287,19 @@ function createNodeRequestHandler(options) {
1227
1287
  }
1228
1288
  if (url.pathname === rscPath) {
1229
1289
  const pathname = stripBasePath(url.searchParams.get("path") || "/", basePath);
1290
+ const requestContext = createRouteRequestContext(
1291
+ req,
1292
+ pathname,
1293
+ url.searchParams.get("path") || "/"
1294
+ );
1230
1295
  const search = new URLSearchParams(url.searchParams.get("search") || "");
1231
1296
  const resolved2 = await withRequestBasename(
1232
1297
  basePath,
1233
1298
  () => router.resolve({
1234
1299
  pathname,
1235
1300
  searchParams: parseSearchParams(search),
1236
- cookies: requestCookies
1301
+ cookies: requestCookies,
1302
+ request: requestContext
1237
1303
  })
1238
1304
  );
1239
1305
  const payload = {
@@ -1273,7 +1339,12 @@ function createNodeRequestHandler(options) {
1273
1339
  () => router.resolve({
1274
1340
  pathname: stripBasePath(url.pathname, basePath),
1275
1341
  searchParams: parseSearchParams(url.searchParams),
1276
- cookies: requestCookies
1342
+ cookies: requestCookies,
1343
+ request: createRouteRequestContext(
1344
+ req,
1345
+ stripBasePath(url.pathname, basePath),
1346
+ url.pathname
1347
+ )
1277
1348
  })
1278
1349
  );
1279
1350
  const initialPayload = {
@@ -1317,7 +1388,7 @@ function createNodeRequestHandler(options) {
1317
1388
  rscEndpoint: rscPath,
1318
1389
  rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
1319
1390
  initialFlightData,
1320
- basename: basePath,
1391
+ basename: resolved?.head?.basename ?? basePath,
1321
1392
  liveReloadPath: liveReloadPath || void 0,
1322
1393
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1323
1394
  })
@@ -1336,7 +1407,7 @@ function createNodeRequestHandler(options) {
1336
1407
  rscEndpoint: rscPath,
1337
1408
  rootHtml,
1338
1409
  initialFlightData,
1339
- basename: basePath,
1410
+ basename: resolved.head.basename ?? basePath,
1340
1411
  liveReloadPath: liveReloadPath || void 0,
1341
1412
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1342
1413
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {