@jsenv/server 17.0.0 → 17.0.1
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/jsenv_server.js
CHANGED
|
@@ -5370,10 +5370,25 @@ const createResourcePattern = (pattern) => {
|
|
|
5370
5370
|
});
|
|
5371
5371
|
}
|
|
5372
5372
|
|
|
5373
|
+
const patternEndsWithSlash =
|
|
5374
|
+
pathnamePatternString.length > 1 && pathnamePatternString.endsWith("/");
|
|
5375
|
+
|
|
5373
5376
|
return {
|
|
5374
5377
|
match: (resource) => {
|
|
5375
5378
|
const [pathname, search, hash] = resourceToParts(resource);
|
|
5376
|
-
let
|
|
5379
|
+
let decodedPathname = decodeURIComponent(pathname);
|
|
5380
|
+
if (
|
|
5381
|
+
patternEndsWithSlash &&
|
|
5382
|
+
decodedPathname.startsWith(pathnamePatternString)
|
|
5383
|
+
) {
|
|
5384
|
+
return {
|
|
5385
|
+
named: {},
|
|
5386
|
+
stars: [decodedPathname.slice(pathnamePatternString.length)],
|
|
5387
|
+
};
|
|
5388
|
+
}
|
|
5389
|
+
let result = patternEndsWithSlash
|
|
5390
|
+
? null
|
|
5391
|
+
: pathnamePattern.match(decodedPathname);
|
|
5377
5392
|
if (!result) {
|
|
5378
5393
|
return null;
|
|
5379
5394
|
}
|
|
@@ -8606,19 +8621,23 @@ const asUrlString = (value) => {
|
|
|
8606
8621
|
return null;
|
|
8607
8622
|
};
|
|
8608
8623
|
|
|
8609
|
-
const serverPluginStaticFiles = ({
|
|
8624
|
+
const serverPluginStaticFiles = ({
|
|
8625
|
+
serverRelativeUrl = "/",
|
|
8626
|
+
directoryUrl,
|
|
8627
|
+
directoryMainFileRelativeUrl = "index.html",
|
|
8628
|
+
}) => {
|
|
8610
8629
|
return {
|
|
8611
8630
|
name: "jsenv:static_files",
|
|
8612
8631
|
routes: [
|
|
8613
8632
|
{
|
|
8614
|
-
endpoint:
|
|
8633
|
+
endpoint: `GET ${serverRelativeUrl}`,
|
|
8615
8634
|
description: "Serve static files.",
|
|
8616
8635
|
fetch: (request, helpers) => {
|
|
8617
8636
|
const urlIsVersioned = new URL(request.url).searchParams.has("v");
|
|
8618
|
-
if (
|
|
8637
|
+
if (directoryMainFileRelativeUrl && request.resource === "/") {
|
|
8619
8638
|
request = {
|
|
8620
8639
|
...request,
|
|
8621
|
-
resource: `/${
|
|
8640
|
+
resource: `/${directoryMainFileRelativeUrl}`,
|
|
8622
8641
|
};
|
|
8623
8642
|
}
|
|
8624
8643
|
const urlObject = new URL(request.resource.slice(1), directoryUrl);
|
|
@@ -8634,7 +8653,7 @@ const serverPluginStaticFiles = ({ directoryUrl, mainFilePath }) => {
|
|
|
8634
8653
|
!urlToExtension(urlObject) &&
|
|
8635
8654
|
!urlToPathname(urlObject).endsWith("/")
|
|
8636
8655
|
) {
|
|
8637
|
-
return new URL(
|
|
8656
|
+
return new URL(directoryMainFileRelativeUrl, directoryUrl);
|
|
8638
8657
|
}
|
|
8639
8658
|
return null;
|
|
8640
8659
|
},
|
package/package.json
CHANGED
|
@@ -2,19 +2,23 @@ import { urlToExtension, urlToPathname } from "@jsenv/urls";
|
|
|
2
2
|
|
|
3
3
|
import { createFileSystemFetch } from "./fetch_filesystem.js";
|
|
4
4
|
|
|
5
|
-
export const serverPluginStaticFiles = ({
|
|
5
|
+
export const serverPluginStaticFiles = ({
|
|
6
|
+
serverRelativeUrl = "/",
|
|
7
|
+
directoryUrl,
|
|
8
|
+
directoryMainFileRelativeUrl = "index.html",
|
|
9
|
+
}) => {
|
|
6
10
|
return {
|
|
7
11
|
name: "jsenv:static_files",
|
|
8
12
|
routes: [
|
|
9
13
|
{
|
|
10
|
-
endpoint:
|
|
14
|
+
endpoint: `GET ${serverRelativeUrl}`,
|
|
11
15
|
description: "Serve static files.",
|
|
12
16
|
fetch: (request, helpers) => {
|
|
13
17
|
const urlIsVersioned = new URL(request.url).searchParams.has("v");
|
|
14
|
-
if (
|
|
18
|
+
if (directoryMainFileRelativeUrl && request.resource === "/") {
|
|
15
19
|
request = {
|
|
16
20
|
...request,
|
|
17
|
-
resource: `/${
|
|
21
|
+
resource: `/${directoryMainFileRelativeUrl}`,
|
|
18
22
|
};
|
|
19
23
|
}
|
|
20
24
|
const urlObject = new URL(request.resource.slice(1), directoryUrl);
|
|
@@ -31,7 +35,7 @@ export const serverPluginStaticFiles = ({ directoryUrl, mainFilePath }) => {
|
|
|
31
35
|
!urlToExtension(urlObject) &&
|
|
32
36
|
!urlToPathname(urlObject).endsWith("/")
|
|
33
37
|
) {
|
|
34
|
-
return new URL(
|
|
38
|
+
return new URL(directoryMainFileRelativeUrl, directoryUrl);
|
|
35
39
|
}
|
|
36
40
|
return null;
|
|
37
41
|
},
|