@jsenv/server 16.0.4 → 16.0.5

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.
@@ -1718,7 +1718,7 @@ const fromNodeRequest = (
1718
1718
  `formData() called on a request with content-type: "${contentType}". multipart/form-data was expected.`,
1719
1719
  );
1720
1720
  }
1721
- const { formidable } = await import("./js/formidable_index.js");
1721
+ const { formidable } = await import("./formidable_index/formidable_index.js");
1722
1722
  const form = formidable({});
1723
1723
  nodeRequest.resume(); // was paused in line #53
1724
1724
  const [fields, files] = await form.parse(nodeRequest);
@@ -3895,9 +3895,19 @@ const applyPatternMatching = ({ url, pattern }) => {
3895
3895
  return applyPattern({ url, pattern });
3896
3896
  };
3897
3897
 
3898
- const resolveAssociations = (associations, baseUrl) => {
3899
- if (baseUrl && typeof baseUrl.href === "string") baseUrl = baseUrl.href;
3900
- assertUrlLike(baseUrl, "baseUrl");
3898
+ const resolveAssociations = (associations, resolver) => {
3899
+ let resolve = () => {};
3900
+ if (typeof resolver === "function") {
3901
+ resolve = resolver;
3902
+ } else if (typeof resolver === "string") {
3903
+ const baseUrl = resolver;
3904
+ assertUrlLike(baseUrl, "baseUrl");
3905
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
3906
+ } else if (resolver && typeof resolver.href === "string") {
3907
+ const baseUrl = resolver.href;
3908
+ assertUrlLike(baseUrl, "baseUrl");
3909
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
3910
+ }
3901
3911
 
3902
3912
  const associationsResolved = {};
3903
3913
  for (const key of Object.keys(associations)) {
@@ -3908,12 +3918,11 @@ const resolveAssociations = (associations, baseUrl) => {
3908
3918
  const valueAssociated = value[pattern];
3909
3919
  let patternResolved;
3910
3920
  try {
3911
- patternResolved = String(new URL(pattern, baseUrl));
3921
+ patternResolved = resolve(pattern);
3912
3922
  } catch {
3913
3923
  // it's not really an url, no need to perform url resolution nor encoding
3914
3924
  patternResolved = pattern;
3915
3925
  }
3916
-
3917
3926
  valueMapResolved[patternResolved] = valueAssociated;
3918
3927
  }
3919
3928
  associationsResolved[key] = valueMapResolved;
@@ -4036,34 +4045,29 @@ const urlChildMayMatch = ({ url, associations, predicate }) => {
4036
4045
  };
4037
4046
 
4038
4047
  const applyAliases = ({ url, aliases }) => {
4039
- let aliasFullMatchResult;
4040
- const aliasMatchingKey = Object.keys(aliases).find((key) => {
4041
- const aliasMatchResult = applyPatternMatching({
4048
+ for (const key of Object.keys(aliases)) {
4049
+ const matchResult = applyPatternMatching({
4042
4050
  pattern: key,
4043
4051
  url,
4044
4052
  });
4045
- if (aliasMatchResult.matched) {
4046
- aliasFullMatchResult = aliasMatchResult;
4047
- return true;
4053
+ if (!matchResult.matched) {
4054
+ continue;
4048
4055
  }
4049
- return false;
4050
- });
4051
- if (!aliasMatchingKey) {
4052
- return url;
4053
- }
4054
- const { matchGroups } = aliasFullMatchResult;
4055
- const alias = aliases[aliasMatchingKey];
4056
- const parts = alias.split("*");
4057
- let newUrl = "";
4058
- let index = 0;
4059
- for (const part of parts) {
4060
- newUrl += `${part}`;
4061
- if (index < parts.length - 1) {
4062
- newUrl += matchGroups[index];
4056
+ const { matchGroups } = matchResult;
4057
+ const alias = aliases[key];
4058
+ const parts = alias.split("*");
4059
+ let newUrl = "";
4060
+ let index = 0;
4061
+ for (const part of parts) {
4062
+ newUrl += `${part}`;
4063
+ if (index < parts.length - 1) {
4064
+ newUrl += matchGroups[index];
4065
+ }
4066
+ index++;
4063
4067
  }
4064
- index++;
4068
+ return newUrl;
4065
4069
  }
4066
- return newUrl;
4070
+ return url;
4067
4071
  };
4068
4072
 
4069
4073
  const matches = (url, patterns) => {
@@ -6489,7 +6493,7 @@ const replacePlaceholdersInHtml = (html, replacers) => {
6489
6493
  });
6490
6494
  };
6491
6495
 
6492
- const clientErrorHtmlTemplateFileUrl = import.meta.resolve("./html/4xx.html");
6496
+ const clientErrorHtmlTemplateFileUrl = import.meta.resolve("./client/4xx/4xx.html");
6493
6497
 
6494
6498
  const jsenvServiceDefaultBody4xx5xx = () => {
6495
6499
  return {
@@ -6568,7 +6572,7 @@ const generateBadStatusResponse = (
6568
6572
  );
6569
6573
  };
6570
6574
 
6571
- const jsenvServerRootDirectoryUrl = import.meta.resolve("../");
6575
+ const jsenvServerRootDirectoryUrl = import.meta.resolve("./");
6572
6576
 
6573
6577
  const jsenvServiceInternalClientFiles = () => {
6574
6578
  return {
@@ -6636,7 +6640,7 @@ const jsenvServiceOpenFile = () => {
6636
6640
  };
6637
6641
 
6638
6642
  const routeInspectorHtmlFileUrl = import.meta.resolve(
6639
- "./html/route_inspector.html",
6643
+ "./client/route_inspector/route_inspector.html",
6640
6644
  );
6641
6645
 
6642
6646
  const jsenvServiceRouteInspector = () => {
@@ -7627,7 +7631,7 @@ const startServer = async ({
7627
7631
  const webSocketSet = new Set();
7628
7632
  let upgradeRequestToWebSocket;
7629
7633
  const loadUpgradeRequestToWebSocket = async () => {
7630
- const { WebSocketServer } = await import("./js/ws.js");
7634
+ const { WebSocketServer } = await import("./ws/ws.js");
7631
7635
  let webSocketServer = new WebSocketServer({ noServer: true });
7632
7636
  stopCallbackSet.add(() => {
7633
7637
  webSocketServer.close();
@@ -7812,7 +7816,7 @@ const PROCESS_TEARDOWN_EVENTS_MAP = {
7812
7816
  exit: STOP_REASON_PROCESS_EXIT,
7813
7817
  };
7814
7818
 
7815
- const internalErrorHtmlFileUrl = import.meta.resolve("./html/500.html");
7819
+ const internalErrorHtmlFileUrl = import.meta.resolve("./client/500/500.html");
7816
7820
 
7817
7821
  const jsenvServiceErrorHandler = ({ sendErrorDetails = false } = {}) => {
7818
7822
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/server",
3
- "version": "16.0.4",
3
+ "version": "16.0.5",
4
4
  "description": "A modern Node.js HTTP server with declarative routing, content negotiation, and WebSocket support",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -42,7 +42,7 @@
42
42
  "launch-editor": "2.10.0",
43
43
  "@jsenv/abort": "4.3.1",
44
44
  "@jsenv/humanize": "1.3.1",
45
- "@jsenv/url-meta": "8.5.5",
45
+ "@jsenv/url-meta": "8.5.6",
46
46
  "@jsenv/utils": "2.2.1",
47
47
  "ws": "8.18.1",
48
48
  "formidable": "3.5.2"
File without changes
File without changes
File without changes