@jsenv/server 17.7.1 → 17.7.2

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.
@@ -853,6 +853,18 @@ main {
853
853
  font-weight: 700;
854
854
  }
855
855
 
856
+ .route_also_method {
857
+ color: #fff;
858
+ text-shadow: 0 1px #0000001a;
859
+ background: var(--method-color);
860
+ border-radius: 3px;
861
+ margin-left: 6px;
862
+ padding: 3px 6px;
863
+ font-family: sans-serif;
864
+ font-size: 11px;
865
+ font-weight: 700;
866
+ }
867
+
856
868
  .route_resource {
857
869
  word-break: break-word;
858
870
  margin-top: 0;
@@ -897,7 +909,7 @@ main {
897
909
  opacity: .85;
898
910
  }
899
911
 
900
- .route_details[data-forbidden] .route_method {
912
+ .route_details[data-forbidden] .route_method, .route_details[data-forbidden] .route_also_method {
901
913
  opacity: .7;
902
914
  filter: grayscale(60%);
903
915
  }
@@ -1835,6 +1847,7 @@ const routesLoadingSignal = M$1(false);
1835
1847
  const RouteDetails = ({
1836
1848
  meta,
1837
1849
  method,
1850
+ methods,
1838
1851
  resource,
1839
1852
  description,
1840
1853
  availableMediaTypes,
@@ -1858,6 +1871,10 @@ const routesLoadingSignal = M$1(false);
1858
1871
  if (selectedPackageName && packageName !== selectedPackageName) {
1859
1872
  return null;
1860
1873
  }
1874
+ // what the router answers beyond the declared method (a GET route
1875
+ // also answers HEAD); a "*" route answers everything, its chip says so
1876
+ const alsoMethods =
1877
+ method === "*" ? [] : methods.filter((m) => m !== method);
1861
1878
 
1862
1879
  return p$3`<details
1863
1880
  class="route_details"
@@ -1867,6 +1884,14 @@ const routesLoadingSignal = M$1(false);
1867
1884
  >
1868
1885
  <summary class="route_summary_container">
1869
1886
  <span class="route_method">${method}</span>
1887
+ ${alsoMethods.map(
1888
+ (alsoMethod) => p$3`<span
1889
+ class="route_also_method"
1890
+ style="--method-color: var(--method-${alsoMethod.toLowerCase()}-color)"
1891
+ title="Also answers ${alsoMethod}"
1892
+ >+${alsoMethod}</span
1893
+ >`,
1894
+ )}
1870
1895
  <p class="route_resource">${resource}</p>
1871
1896
  ${method === "GET" && !forbidden
1872
1897
  ? p$3`<a
@@ -6959,6 +6959,7 @@ const createRoute = ({
6959
6959
  }
6960
6960
  return {
6961
6961
  method,
6962
+ methods,
6962
6963
  resource,
6963
6964
  description,
6964
6965
  availableMediaTypes,
@@ -31,7 +31,7 @@ await startServer({
31
31
  | `GET /*` | anything, with the path in `request.params[0]` |
32
32
  | `GET *` | anything: a catch-all, put it last |
33
33
 
34
- A `GET` route also answers `HEAD`: the response is built the same way and sent without its body.
34
+ A `GET` route also answers `HEAD`: the response is built the same way and sent without its body. When building that body is costly, declare a `HEAD` route for the same resource before the `GET` one: it answers `HEAD` in its place.
35
35
 
36
36
  Only `*` widens a pattern. Routes are tried in order, so a route covering others (`GET /docs/*`, `GET *`) goes after them. `fetch` can be async; returning `null` or `undefined` declines the request and the next route is tried.
37
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/server",
3
- "version": "17.7.1",
3
+ "version": "17.7.2",
4
4
  "type": "module",
5
5
  "description": "A modern Node.js HTTP server with declarative routing, content negotiation, and WebSocket support",
6
6
  "repository": {
@@ -443,6 +443,17 @@
443
443
  background: var(--method-color);
444
444
  border-radius: 3px;
445
445
  }
446
+ .route_also_method {
447
+ margin-left: 6px;
448
+ padding: 3px 6px;
449
+ color: #fff;
450
+ font-weight: 700;
451
+ font-size: 11px;
452
+ font-family: sans-serif;
453
+ text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
454
+ background: var(--method-color);
455
+ border-radius: 3px;
456
+ }
446
457
  .route_resource {
447
458
  margin-top: 0;
448
459
  margin-bottom: 0;
@@ -486,7 +497,8 @@
486
497
  border-color: var(--forbidden-border-color);
487
498
  opacity: 0.85;
488
499
  }
489
- .route_details[data-forbidden] .route_method {
500
+ .route_details[data-forbidden] .route_method,
501
+ .route_details[data-forbidden] .route_also_method {
490
502
  opacity: 0.7;
491
503
  filter: grayscale(60%);
492
504
  }
@@ -1428,6 +1440,7 @@
1428
1440
  const RouteDetails = ({
1429
1441
  meta,
1430
1442
  method,
1443
+ methods,
1431
1444
  resource,
1432
1445
  description,
1433
1446
  availableMediaTypes,
@@ -1451,6 +1464,10 @@
1451
1464
  if (selectedPackageName && packageName !== selectedPackageName) {
1452
1465
  return null;
1453
1466
  }
1467
+ // what the router answers beyond the declared method (a GET route
1468
+ // also answers HEAD); a "*" route answers everything, its chip says so
1469
+ const alsoMethods =
1470
+ method === "*" ? [] : methods.filter((m) => m !== method);
1454
1471
 
1455
1472
  return html`<details
1456
1473
  class="route_details"
@@ -1460,6 +1477,14 @@
1460
1477
  >
1461
1478
  <summary class="route_summary_container">
1462
1479
  <span class="route_method">${method}</span>
1480
+ ${alsoMethods.map(
1481
+ (alsoMethod) => html`<span
1482
+ class="route_also_method"
1483
+ style="--method-color: var(--method-${alsoMethod.toLowerCase()}-color)"
1484
+ title="Also answers ${alsoMethod}"
1485
+ >+${alsoMethod}</span
1486
+ >`,
1487
+ )}
1463
1488
  <p class="route_resource">${resource}</p>
1464
1489
  ${method === "GET" && !forbidden
1465
1490
  ? html`<a
@@ -766,6 +766,7 @@ const createRoute = ({
766
766
  }
767
767
  return {
768
768
  method,
769
+ methods,
769
770
  resource,
770
771
  description,
771
772
  availableMediaTypes,