@fastly/compute-js-static-publish 2.4.1 → 2.4.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.
package/README.md CHANGED
@@ -50,16 +50,16 @@ npx @fastly/compute-js-static-publish \
50
50
 
51
51
  Any configuration options will be written to a `static-publish.rc.js` file.
52
52
 
53
- | Option | Default | Description |
54
- |------------------|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
- | `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
56
- | `output` | `./compute-js` | The directory in which to create the Compute@Edge application. |
57
- | `public-dir` | (None) | **Required**. The root of the directory that contains your website's public files. Files at this path will be served by the generated Compute@Edge application. |
58
- | `static-dir` | (None) | A subdirectory of `--public-dir` that contains the website's static assets. Files at this path will be cached by the browser for 1 year. Use versioned or hashed filenames to avoid serving stale assets. |
59
- | `auto-index` | `index.html,index.htm` | Handle request paths that end in `/` by appending these names (comma-separated), in the specified order. By default, if `/path/to/a/` is requested, attempt to serve `/path/to/a/index.html`, then `/path/to/a/index.htm`. |
60
- | `auto-ext` | `.html,.htm` | Handle request paths that do not end in `/` by appending these extensions (comma-separated), in the specified order. By default, if `/path/to/a` is requested, attempt to serve `/path/to/a`, `/path/to/a.html`, then `/path/to/a.htm`. |
61
- | `spa` | (None) | Serve this file when the request path does not match known paths – with a `200` status code. Useful for apps that use [client-side routing](https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing). |
62
- | `not-found-page` | `<public-dir>/404.html` | Serve this file when the request path does not match known paths – with a `404` status code. Useful for a custom 404 error page. |
53
+ | Option | Default | Description |
54
+ |------------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
+ | `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
56
+ | `output` | `./compute-js` | The directory in which to create the Compute@Edge application. |
57
+ | `public-dir` | (None) | **Required**. The root of the directory that contains your website's public files. Files at this path will be served by the generated Compute@Edge application. |
58
+ | `static-dir` | (None) | A subdirectory of `--public-dir` that contains the website's static assets. Files at this path will be cached by the browser for 1 year. Use versioned or hashed filenames to avoid serving stale assets. |
59
+ | `auto-index` | `index.html,index.htm` | Attempt to handle request paths by appending these names (comma-separated), in the specified order. If a path does not end in a slash, a slash is added automatically. By default, if `/path/to/a/` is requested, attempt to serve `/path/to/a/index.html`, then `/path/to/a/index.htm`. |
60
+ | `auto-ext` | `.html,.htm` | Handle request paths that do not end in `/` by appending these extensions (comma-separated), in the specified order. By default, if `/path/to/a` is requested, attempt to serve `/path/to/a`, `/path/to/a.html`, then `/path/to/a.htm`. |
61
+ | `spa` | (None) | Serve this file when the request path does not match known paths – with a `200` status code. Useful for apps that use [client-side routing](https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing). |
62
+ | `not-found-page` | `<public-dir>/404.html` | Serve this file when the request path does not match known paths – with a `404` status code. Useful for a custom 404 error page. |
63
63
 
64
64
  On subsequent builds of your Compute@Edge application, `compute-js-static-publish` will run with a special flag, `build-static`, reading from stored configuration, then scanning the `--public-dir` directory to recreate `./src/statics.js`.
65
65
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "2.4.1",
4
+ "version": "2.4.2",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -6,15 +6,15 @@ import { staticAssets, spaFile, notFoundPageFile, autoIndex, autoExt } from './s
6
6
  const router = new Router();
7
7
 
8
8
  function getMatchingRequestPath(path) {
9
- // If the path being looked up does not end in a slash, it has to
10
- // match exactly one of the assets
11
- if(!path.endsWith('/')) {
12
9
 
10
+ if(!path.endsWith('/')) {
11
+ // A path that does not end in a slash can match an asset directly
13
12
  if (staticAssets.getAsset(path) != null) {
14
13
  return path;
15
14
  }
16
15
 
17
- // try auto-ext
16
+ // ... or, we can try auto-ext:
17
+ // looks for an asset that has the specified suffix (usually extension, such as .html)
18
18
  if(autoExt != null) {
19
19
  for (const extEntry of autoExt) {
20
20
  let pathWithExt = path + extEntry;
@@ -23,15 +23,20 @@ function getMatchingRequestPath(path) {
23
23
  }
24
24
  }
25
25
  }
26
-
27
- return null;
28
-
29
26
  }
30
27
 
31
- // try auto-index
28
+ // try auto-index:
29
+ // treats the path as a directory, and looks for an asset with the specified
30
+ // suffix (usually an index file, such as index.html)
31
+ let dir = path;
32
+ // remove all slashes from end, and add one trailing slash
33
+ while(dir.endsWith('/')) {
34
+ dir = dir.slice(0, -1);
35
+ }
36
+ dir = dir + '/';
32
37
  if(autoIndex != null) {
33
38
  for (const indexEntry of autoIndex) {
34
- let indexPath = path + indexEntry;
39
+ let indexPath = dir + indexEntry;
35
40
  if (staticAssets.getAsset(indexPath) != null) {
36
41
  return indexPath;
37
42
  }