@fastly/compute-js-static-publish 8.1.0-beta.7 → 8.1.0-beta.9
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/CHANGELOG.md +10 -2
- package/DOCUMENTATION.md +112 -70
- package/MIGRATING.md +45 -15
- package/README.md +6 -5
- package/README.short.md +6 -5
- package/build/cli/cli/commands/manage/clean.js +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +1 -1
- package/build/cli/cli/commands/manage/index.js +2 -2
- package/build/cli/cli/commands/manage/publish-content.js +1 -1
- package/build/cli/cli/commands/manage/status.js +1 -1
- package/build/cli/cli/commands/manage/template/index.js +1 -1
- package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/template/init.js +11 -4
- package/build/cli/cli/commands/scaffold/app-template.js +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.js +1 -1
- package/build/cli/cli/commands/scaffold/index.js +5 -5
- package/build/cli/cli/hono/build.d.ts +21 -14
- package/build/cli/cli/hono/build.d.ts.map +1 -1
- package/build/cli/cli/hono/build.js +119 -76
- package/build/cli/cli/managed/app.js +4 -4
- package/build/cli/cli/managed/command-helpers.js +6 -6
- package/build/cli/cli/managed/project-file.js +6 -6
- package/build/cli/cli/managed/template-init.js +3 -3
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +2 -2
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +2 -14
- package/build/cli/cli/storage/kv-store-provider.d.ts +2 -2
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +2 -1
- package/build/cli/cli/storage/s3-storage-provider.d.ts +2 -2
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +4 -3
- package/build/cli/cli/storage/storage-provider.d.ts +3 -1
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +16 -0
- package/build/cli/cli/util/kv-store.d.ts +1 -1
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.d.ts +4 -3
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/template-settings.d.ts.map +1 -1
- package/build/cli/models/config/template-settings.js +34 -9
- package/build/server/hono/compose.d.ts +51 -0
- package/build/server/hono/compose.d.ts.map +1 -0
- package/build/server/hono/compose.js +93 -0
- package/build/server/hono/index.d.ts +1 -1
- package/build/server/hono/index.d.ts.map +1 -1
- package/build/server/hono/index.js +1 -1
- package/build/server/models/config/static-publish-rc.d.ts +4 -3
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +6 -1
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/kv-store-provider.js +1 -0
- package/build/server/server/storage/s3-storage-provider.d.ts +2 -2
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +5 -2
- package/build/server/server/storage/storage-provider.d.ts +12 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/package.json +2 -2
- package/resources/template-init/hono/_example.ts +14 -13
- package/resources/templates/hono/package-lock.json +40 -40
- package/resources/templates/hono/package.json +2 -2
- package/resources/templates/hono/scripts/template_postinstall.js +5 -5
- package/resources/templates/hono/scripts/template_prebuild.js +6 -6
- package/resources/templates/hono/scripts/template_watch.js +5 -4
- package/resources/templates/hono/src/hono-compose.generated.d.ts +5 -0
- package/resources/templates/hono/src/index.ts +14 -14
- package/resources/templates/plain/package-lock.json +40 -40
- package/resources/templates/plain/package.json +2 -2
- package/build/server/hono/extensions.d.ts +0 -50
- package/build/server/hono/extensions.d.ts.map +0 -1
- package/build/server/hono/extensions.js +0 -70
- package/resources/templates/hono/src/hono-extensions.generated.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -12,8 +12,8 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
|
|
|
12
12
|
### Added
|
|
13
13
|
|
|
14
14
|
- `scaffold --template hono` (and `managed.template: 'hono'` in a managed project): a TypeScript Hono app. `src/index.ts` uses `selectCollection()`, `serveStatic()`, and `serveFallback()` of `@fastly/compute-js-static-publish/hono`, and `fire()` of `@fastly/hono-fastly-compute`. The app has `tsconfig.json`, and `typescript` as a dev dependency; the build does not check types (run `npx tsc`). In a managed project, a change of `managed.template` generates the app again with the new template, and changes the fingerprint.
|
|
15
|
-
-
|
|
16
|
-
- Examples of
|
|
15
|
+
- Composing plugin modules in the `hono` template: plugins in `hono-compose/` default-export `definePlugin()` (from `@fastly/compute-js-static-publish/hono`), with a function for each phase that they use: `middleware`, `routes` (before the published files), and `afterFilesRoutes` (for the requests that no published file matches). Each phase function gets the app, the options of the plugin, and the helpers of the app (`serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer`). `c.env` in a plugin has the types of its bindings. The build bundles them into the app; the packages that the app provides stay imports. Options come from `templateOptions.hono.compose.plugins` and bindings from `templateOptions.hono.bindings`, and `build.hono.composeDir` sets another folder. A file named `index` in the folder is reserved. `template init` makes or updates the folder (with a `.gitignore` for `node_modules/`), and `template init --check` fails with the new error code `template-init-needed` if it is out of date. `dev -- --watch` and `npm run dev:watch` also watch the folder. `status --json` has `template`, with the packages that the template provides.
|
|
16
|
+
- Examples of plugins in `examples/hono/` (in the repository, not in the npm package): `grip` (realtime streams and Server-Sent Events with Fastly Fanout) and `oauth` (a login with GitHub or Google).
|
|
17
17
|
- Hono support: `@fastly/compute-js-static-publish/hono`. `fromStaticPublishRc(rc)` (or `fromPublisherServer(server)`) returns `serveStatic()` (middleware that serves the published files with `serveRequest()`, and calls the next handler if no file matches; the option `onMissing` replaces `collectionSelection.onMissing` for one route), `staticResponse(c)` (the same response for use in a handler, or `null`; never the SPA file or the 404 page), `serveFallback()` (for `app.notFound()`: the SPA file or the 404 page), `fallbackResponse(c)` (the same response for use in a handler, or `null`), `isCollectionAvailable(c)` (whether the selected collection, or another one, is published and not expired), `selectCollection()` (collection selection for a Hono app; it sets `c.var.staticPublisher`, and `serveStatic()` and `serveFallback()` use the selected collection), and `publisherServer`. The type `StaticPublisherVariables` is for the variables of the app. The options `status` and `headers` change the response of a file. `hono` v4 is an optional peer dependency. This replaces `@fastly/hono-compute-js-static-publish`, which supports only v6 and v7; `MIGRATING.md` has the steps.
|
|
18
18
|
- `--project-dir`: run a command for the app in another directory, for example from the root of the repo in CI. All relative paths are then relative to that directory.
|
|
19
19
|
- `--version`: print the version of this package. It works in any directory.
|
|
@@ -52,6 +52,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
|
|
|
52
52
|
- `PublisherServer`: the options `status` and `headers` of `serveRequest()` and `serveFallback()` change the status and the headers of the response of a file, for one call. For a status other than `2xx`, the server does not evaluate the preconditions of the request.
|
|
53
53
|
- `PublisherServer`: `serveRequestStreaming()`, `serveFallbackStreaming()`, and `serveCachedStreaming()` return `{ response, fillPromise }`. On a Fastly service with `@fastly/js-compute` 4.2 or later (not in `fastly compute serve`), a response cache fill for a body with a known length streams the body to the visitor and into the cache at the same time. Pass `fillPromise` to `event.waitUntil()`. A body that does not have its declared length is not cached, and the next fill reads the whole body first. The `plain` template and the Hono helpers use them.
|
|
54
54
|
- `PublisherServer`: the function of `serveCached()` can return `{ response, length }`. With `length: null`, the response is not cached.
|
|
55
|
+
- `StorageProvider.getEntry()` takes an optional third parameter, `options` (type `GetEntryOptions`). Its `ttl` sets how long, in seconds, a provider that caches what it reads keeps the entry.
|
|
55
56
|
|
|
56
57
|
### Changed
|
|
57
58
|
|
|
@@ -70,6 +71,12 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
|
|
|
70
71
|
- `collections promote` from a collection that does not exist stops with the message "Collection '…' does not exist." (exit `2`). Before, it stopped with an uncaught error.
|
|
71
72
|
- `collections delete` of a collection that does not exist says "Nothing to delete." It still succeeds, as before.
|
|
72
73
|
- `staticPublisherWorkingDir` in `static-publish.rc.js` can be a path outside the directory of the file, for example `../static-publisher`. It must start with `./` or `../`, and it must not be the directory of `static-publish.rc.js` or a directory above it (for example `./`, `..`, or `../..`). Before, the value had to start with `./`. A value that breaks the rule stops the command before it writes anything.
|
|
74
|
+
- S3 mode: the server keeps the files that it reads from storage in the Fastly cache for 1 year. It was 1 hour. With a response cache `maxAge` of 1 hour or more, a response-cache miss then usually also read the file from storage. The key of a file has the hash of its content, so a cached copy does not get out of date. The cached files have the new surrogate key `<publishId>-files`. A publish does not purge it. The settings and the index are still kept for 1 hour.
|
|
75
|
+
- S3-compatible storage is no longer a beta feature. The docs, the help, and the messages of the CLI do not show "Beta" for it now.
|
|
76
|
+
|
|
77
|
+
### Updated
|
|
78
|
+
|
|
79
|
+
- Scaffolded apps and the apps of managed projects use `@fastly/js-compute` `^4.4.0` and `@fastly/cli` `^17.0.0`. Before, they used `^4.0.0` and `^16.0.0`.
|
|
73
80
|
|
|
74
81
|
### Deprecated
|
|
75
82
|
|
|
@@ -79,6 +86,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
|
|
|
79
86
|
|
|
80
87
|
- `PublisherServer`: a request for the 404 page with an `If-None-Match` that matched its `ETag` (or an `If-Modified-Since` after its time) got a `304` with no body. Now the server evaluates the preconditions only for a `2xx` response, as RFC 9110 says, so the response is always the `404` with the page.
|
|
81
88
|
- `scaffold` now escapes the values that it writes into `fastly.toml`. Before, a `"` or a `\` in `--name`, `--description`, or `--author`, or a KV Store name with a character such as `.`, gave a `fastly.toml` that was not valid.
|
|
89
|
+
- `collections promote` and `collections update-expiration` (KV Store): the command sometimes stopped with `400 Bad request: must include valid content-length header` when it wrote the index of the collection. The command sent the index as a stream, with no `Content-Length`. Now it reads the index into memory and sends it with a `Content-Length`. In S3 mode, the commands now also send the index and the settings with a known length.
|
|
82
90
|
|
|
83
91
|
## [8.0.2] - 2026-11-16
|
|
84
92
|
|
package/DOCUMENTATION.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> NOTE: `@fastly/compute-js-static-publish` is provided as a Fastly Labs product. Visit the [Fastly Labs](https://www.fastlylabs.com/) site for terms of use.
|
|
4
4
|
|
|
5
5
|
> [!NOTE]
|
|
6
|
-
> v8 adds
|
|
6
|
+
> v8 adds support for S3-compatible storage, such as Fastly [Object Storage](https://www.fastly.com/products/storage). For more details, see the [S3-compatible storage](#-using-s3-compatible-storage) section.
|
|
7
7
|
|
|
8
8
|
> [!NOTE]
|
|
9
9
|
> These docs are for v7 or newer, a major rewrite that adds powerful new features such as named collections.
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
## 📖 Table of Contents
|
|
16
16
|
|
|
17
17
|
- [✨ Key Features](#-key-features)
|
|
18
|
+
- [🆕 New in 8.1](#-new-in-81)
|
|
18
19
|
- [🏁 Quick Start](#-quick-start)
|
|
19
20
|
- [📦 Fastly KV Store](#-using-the-fastly-kv-store)
|
|
20
|
-
- [🎁 S3 Compatible Storage](#-using-s3-compatible-storage
|
|
21
|
+
- [🎁 S3 Compatible Storage](#-using-s3-compatible-storage)
|
|
21
22
|
- [⚙️ Configuring `static-publish.rc.js`](#️-configuring-static-publishrcjs)
|
|
22
23
|
- [🧾 Config for Publishing and Server: `publish-content.config.js`](#-config-for-publishing-and-server-publish-contentconfigjs)
|
|
23
24
|
- [📦 Collections (Publish, Preview, Promote)](#-collections-publish-preview-promote)
|
|
@@ -34,18 +35,34 @@ Serve static websites and web apps at the edge — no backends and no CDN in
|
|
|
34
35
|
|
|
35
36
|
`@fastly/compute-js-static-publish` helps you deploy and serve static files using [Fastly Compute](https://developer.fastly.com/learning/compute/) for fast, cacheable, and content-addressed delivery. The library can be configured to store your data in either of the following:
|
|
36
37
|
* Fastly [Key Value Store](https://www.fastly.com/products/kv-store)
|
|
37
|
-
* S3-compatible storage, such as Fastly [Object Storage](https://www.fastly.com/products/storage)
|
|
38
|
+
* S3-compatible storage, such as Fastly [Object Storage](https://www.fastly.com/products/storage)
|
|
38
39
|
|
|
39
40
|
## ✨ Key Features
|
|
40
41
|
|
|
41
42
|
- 📦 Easy to scaffold and deploy
|
|
42
|
-
- 🚀 Content stored using hashed keys, in Fastly KV Store or S3-compatible storage
|
|
43
|
+
- 🚀 Content stored using hashed keys, in Fastly KV Store or S3-compatible storage, including Fastly Object Storage
|
|
43
44
|
- 🔁 Publish new content without needing to deploy new Wasm binaries
|
|
44
45
|
- 🗂 Organize releases into named collections which can be previewed (e.g. `live`, `staging`, `preview-123`)
|
|
45
46
|
- 🧼 Cleanup tools to remove expired or orphaned files
|
|
46
47
|
- ⚙️ Configurable per-collection server configurations (e.g. fallback files)
|
|
47
48
|
- 🔒 Supports Brotli/gzip compression, conditional GET, and long cache TTLs
|
|
48
49
|
|
|
50
|
+
## 🆕 New in 8.1
|
|
51
|
+
|
|
52
|
+
- **Managed projects:** keep only `static-publish.project.js` in your repo. The CLI generates the app, and `dev`, `deploy`, `status`, `upgrade`, and `eject` work with it. ([Managed and ejected apps](#managed-and-ejected-apps))
|
|
53
|
+
- **Previews:** serve another collection for a request, selected by host, path, query, cookie, or header. ([Previews](#-previews-collection-selection))
|
|
54
|
+
- **Hidden files:** publish files that the server does not serve for a request, for your own code to read. Deploy your app with 8.1 before you publish hidden files: an app built with 8.0 does not serve a collection that has hidden files. ([Hidden files](#hidden-files))
|
|
55
|
+
- **Hono:** the `hono` template (`--template=hono`), with your own middleware and routes as plugin modules in `hono-compose/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](#-using-hono))
|
|
56
|
+
- **CI:** `--json` output, exit codes, error codes, `--project-dir`, and `--non-interactive`. ([Using the CLI in CI](#-using-the-cli-in-ci))
|
|
57
|
+
- **Streaming response cache:** on a cache miss, the file goes to the visitor and into the cache at the same time, so the visitor does not wait for the whole file, and the request uses less memory. Apps from the `plain` and `hono` templates do this; in your own code, use `serveRequestStreaming()` and pass `fillPromise` to `event.waitUntil()`. It needs `@fastly/js-compute` 4.2 or later on a Fastly service. ([Streaming the response into the cache](#streaming-the-response-into-the-cache))
|
|
58
|
+
|
|
59
|
+
Before you upgrade, read [CHANGELOG.md](CHANGELOG.md). These changes can break something:
|
|
60
|
+
|
|
61
|
+
- The name of a new collection must be a DNS label: lowercase `a-z`, `0-9`, and `-`, from 1 to 63 characters, with no `-` at the start or the end. A collection that exists continues to work with another name, with a warning.
|
|
62
|
+
- A usage or config error exits with `2`. Before, every error exited with `1`.
|
|
63
|
+
- `collectionSelector.fromCookie()`: the activate and reset paths redirect with `308`. Before, they used `302`.
|
|
64
|
+
- `PublisherServer`: the fields `serverTiming`, `settingsCached`, and `assetEntryMapCache` are read-only (deprecated). An assignment to them throws a `TypeError` (and is a TypeScript error).
|
|
65
|
+
|
|
49
66
|
---
|
|
50
67
|
|
|
51
68
|
## 🏁 Quick Start
|
|
@@ -111,7 +128,7 @@ This command uploads your static files to the KV Store and applies the server co
|
|
|
111
128
|
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
112
129
|
```
|
|
113
130
|
|
|
114
|
-
### 🎁 Using S3 Compatible Storage
|
|
131
|
+
### 🎁 Using S3 Compatible Storage
|
|
115
132
|
|
|
116
133
|
#### 1. Scaffold a Compute App
|
|
117
134
|
|
|
@@ -246,7 +263,7 @@ my-site/
|
|
|
246
263
|
|
|
247
264
|
The project file has the settings that an ejected app has in its two files:
|
|
248
265
|
|
|
249
|
-
- The top level has the fields of `static-publish.rc.js` (`storageMode`, `kvStore` or `s3`, `publishId`, `defaultCollectionName`, `staticPublisherWorkingDir`, `collectionSelection`), and the settings of the template (`build` and `templateOptions`, see [
|
|
266
|
+
- The top level has the fields of `static-publish.rc.js` (`storageMode`, `kvStore` or `s3`, `publishId`, `defaultCollectionName`, `staticPublisherWorkingDir`, `collectionSelection`), and the settings of the template (`build` and `templateOptions`, see [Composing plugin modules](#composing-plugin-modules)).
|
|
250
267
|
- `publishContent` has the fields of `publish-content.config.js`. `publish-content --config <file>` replaces it for one run.
|
|
251
268
|
- `managed` has the settings of the generated app (`name`, `description`, `authors`, `serviceId`, `staticPublishVersion`, the version of this package that the project uses, and `fastlyToml`, see below).
|
|
252
269
|
|
|
@@ -401,7 +418,7 @@ const rc = {
|
|
|
401
418
|
export default rc;
|
|
402
419
|
```
|
|
403
420
|
|
|
404
|
-
### Using S3-compatible storage
|
|
421
|
+
### Using S3-compatible storage
|
|
405
422
|
|
|
406
423
|
#### Fields:
|
|
407
424
|
|
|
@@ -890,7 +907,7 @@ If you do need to rebuild and redeploy the Compute app, simply run:
|
|
|
890
907
|
npm run fastly:deploy
|
|
891
908
|
```
|
|
892
909
|
|
|
893
|
-
### Using S3-compatible storage
|
|
910
|
+
### Using S3-compatible storage
|
|
894
911
|
|
|
895
912
|
#### Local development
|
|
896
913
|
|
|
@@ -1145,6 +1162,7 @@ publisherServer.setResponseCache({ maxAge: 3600, maxBodySize: 4 * 1024 * 1024 })
|
|
|
1145
1162
|
- If several requests miss the same response at the same time, one request produces it, and the others wait for it.
|
|
1146
1163
|
- Only `200` and `404` responses are cached. Conditional requests (`304`) and `HEAD` requests are answered from the cached response.
|
|
1147
1164
|
- Each cached response has the surrogate key `<publishId>-<collectionName>`. After you publish, `publish-content` purges this key (see [`--fastly-service-id`](#publish-content)), so the next request gets the new content. `collections promote` and `collections delete` purge the key of the collection that they change.
|
|
1165
|
+
- In S3 mode, the server also keeps the settings, the index, and the files that it reads from storage in the Fastly cache. The settings and the index are kept for 1 hour, with the surrogate key of the collection. The files are kept for 1 year, with the surrogate key `<publishId>-files`, because the key of a file has the hash of its content. Thus after a publish, a file that did not change is read from the cache, not from storage. A publish does not purge `<publishId>-files`. To remove the cached copies of all files, purge it yourself.
|
|
1148
1166
|
|
|
1149
1167
|
`serveRequest()` uses the response cache automatically. If you call `getMatchingAsset()` and `serveAsset()` directly, wrap them in `serveCached()`. When a response is not cached yet, `serveCached()` calls your function to produce it, with a `GET` request that has no conditional headers:
|
|
1150
1168
|
|
|
@@ -1177,7 +1195,7 @@ async function handleRequest(event) {
|
|
|
1177
1195
|
|
|
1178
1196
|
With `event.waitUntil()`, the fill continues after your handler returns, also if the visitor disconnects. Without it, the fill stops when your handler returns, and nothing is cached. `fillPromise` never rejects.
|
|
1179
1197
|
|
|
1180
|
-
The scaffolded app of the `plain` template and the [Hono](#-using-hono) helpers use these methods.
|
|
1198
|
+
The scaffolded app of the `plain` template and the [Hono](#-using-hono) helpers use these methods. Apps scaffolded before 8.1.0 call `serveRequest()`, so their fill does not stream. To stream, change `src/index.js` of such an app as the example above shows.
|
|
1181
1199
|
|
|
1182
1200
|
The fill streams only on a Fastly service with `@fastly/js-compute` 4.2 or later. With an earlier version, in `fastly compute serve`, or for a body with a length that is not known, the fill reads the whole body first, as `serveCached()` does, and `fillPromise` is already resolved.
|
|
1183
1201
|
|
|
@@ -1204,9 +1222,9 @@ npx @fastly/compute-js-static-publish@beta --template hono --root-dir=./public -
|
|
|
1204
1222
|
|
|
1205
1223
|
The app is TypeScript: `src/index.ts`, with code like the example below, and `tsconfig.json`. Add your own routes in `src/index.ts`. The build (`js-compute-runtime ./src/index.ts`) removes the types, but does not check them. To check the types, run `npx tsc` in the app. The app has `typescript` as a dev dependency.
|
|
1206
1224
|
|
|
1207
|
-
###
|
|
1225
|
+
### Composing plugin modules
|
|
1208
1226
|
|
|
1209
|
-
To add your own middleware and routes to the `hono` template, put modules in the
|
|
1227
|
+
To add your own middleware and routes to the `hono` template, put plugin modules in the folder `hono-compose/`. The app composes them with the published files. In a managed project, this is the only way to add code, because the CLI generates the app. In an ejected app, you can also edit `src/index.ts`.
|
|
1210
1228
|
|
|
1211
1229
|
`scaffold --template hono` makes the folder next to the project file (managed) or next to `compute-js/` (ejected). To make it later, or to update it, run:
|
|
1212
1230
|
|
|
@@ -1215,35 +1233,59 @@ npx @fastly/compute-js-static-publish@beta template init
|
|
|
1215
1233
|
```
|
|
1216
1234
|
|
|
1217
1235
|
```
|
|
1218
|
-
hono-
|
|
1236
|
+
hono-compose/
|
|
1219
1237
|
├── package.json # Your dependencies, and the peer dependencies on the packages that the app provides
|
|
1220
1238
|
├── tsconfig.json # For your editor
|
|
1221
1239
|
├── .gitignore # Ignores node_modules/
|
|
1222
|
-
├── 10-auth.ts # A
|
|
1223
|
-
├── api.ts # A
|
|
1224
|
-
├── _example.ts # An example, not a
|
|
1225
|
-
└── lib/ # Your helpers (not
|
|
1240
|
+
├── 10-auth.ts # A plugin
|
|
1241
|
+
├── api.ts # A plugin
|
|
1242
|
+
├── _example.ts # An example, not a plugin (the name starts with _)
|
|
1243
|
+
└── lib/ # Your helpers (not plugins)
|
|
1226
1244
|
```
|
|
1227
1245
|
|
|
1228
|
-
- **
|
|
1229
|
-
- **The name** of a
|
|
1230
|
-
- **The phases:** a
|
|
1246
|
+
- **Plugins** are the files directly in the folder, with the extension `.ts`, `.mts`, `.js`, or `.mjs`. Files that start with `_` or `.`, and `.d.ts` files, are not plugins. The build does not look in subfolders, so use them, for example `lib/`, for your helpers.
|
|
1247
|
+
- **The name** of a plugin is the file name without the number prefix and the extension: `10-auth.ts` is `auth`. Two plugins with the same name are an error. `index` is a reserved name: a file `index.ts` (or `.js`, `.mjs`, `.mts`) stops the build.
|
|
1248
|
+
- **The phases:** a plugin adds its handlers to the app in one or more phases. In each phase, the app takes the plugins in the order of the file names (add a number prefix to set the order). The phases are on two axes:
|
|
1231
1249
|
|
|
1232
1250
|
```
|
|
1233
|
-
selectCollection()
|
|
1251
|
+
selectCollection()
|
|
1252
|
+
middleware processing: wraps all of the routing below
|
|
1253
|
+
routes routing: the first route that answers wins
|
|
1254
|
+
→ published files (serveStatic())
|
|
1255
|
+
→ afterFilesRoutes
|
|
1256
|
+
→ serveFallback()
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
- **Processing:** `middleware` wraps each request, for example a login check, a header on each response, or the time of a request. In a middleware, the code before `await next()` runs before the routes. The code after it runs after the response is made, also when a published file answered, and in the reverse order of the plugins. All plugins add their middleware before any plugin adds its routes, so a middleware such as a login check also applies to the routes of the other plugins.
|
|
1260
|
+
- **Routing:** the routes that can answer a request, in this order. The first one that answers wins.
|
|
1261
|
+
- `routes`: before the published files. A route here wins over a file at the same path, for example an API.
|
|
1262
|
+
- The published files (`serveStatic()`).
|
|
1263
|
+
- `afterFilesRoutes`: only for the requests that no published file matches, before the SPA file or the 404 page. A file at the same path wins, for example for a redirect from an old URL, which stops when a file is published at that URL again. The published files are served only for `GET` and `HEAD`, so these routes also get all other methods.
|
|
1264
|
+
|
|
1265
|
+
A middleware that measures the time of each request, with the code before and after `await next()`:
|
|
1266
|
+
|
|
1267
|
+
```ts
|
|
1268
|
+
// hono-compose/05-timing.ts
|
|
1269
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1270
|
+
|
|
1271
|
+
export default definePlugin((app) => {
|
|
1272
|
+
app.use('*', async (c, next) => {
|
|
1273
|
+
const start = performance.now();
|
|
1274
|
+
await next();
|
|
1275
|
+
console.log(`${c.req.method} ${c.req.path} ${c.res.status} ${(performance.now() - start).toFixed(1)} ms`);
|
|
1276
|
+
});
|
|
1277
|
+
});
|
|
1234
1278
|
```
|
|
1235
1279
|
|
|
1236
|
-
|
|
1237
|
-
- `beforeFiles`: before the published files.
|
|
1238
|
-
- `afterFiles`: after the published files. These handlers get only the requests that no published file matches, for example to make a page for a path that has no file, before the 404 page. The published files are served only for `GET` and `HEAD`, so these handlers also get all other methods.
|
|
1280
|
+
The time ends when the response is made. The body of a large file can still be on its way to the visitor then.
|
|
1239
1281
|
|
|
1240
|
-
A
|
|
1282
|
+
A plugin default-exports `definePlugin()`. Give it a function for each phase that the plugin uses. Each function gets the Hono app, the options of the plugin, and the helpers of the app (see below), and adds handlers with `app.use()`, `app.get()`, `app.post()`, and the other methods of Hono. With only a function in place of the object, the function is the `middleware` phase:
|
|
1241
1283
|
|
|
1242
1284
|
```ts
|
|
1243
|
-
// hono-
|
|
1244
|
-
import {
|
|
1285
|
+
// hono-compose/10-header.ts
|
|
1286
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1245
1287
|
|
|
1246
|
-
export default
|
|
1288
|
+
export default definePlugin((app, options?: { value?: string }) => {
|
|
1247
1289
|
app.use('*', async (c, next) => {
|
|
1248
1290
|
await next();
|
|
1249
1291
|
c.header('x-site', options?.value ?? 'default');
|
|
@@ -1252,47 +1294,47 @@ export default defineExtension((app, options?: { value?: string }) => {
|
|
|
1252
1294
|
```
|
|
1253
1295
|
|
|
1254
1296
|
```ts
|
|
1255
|
-
// hono-
|
|
1256
|
-
import {
|
|
1297
|
+
// hono-compose/api.ts
|
|
1298
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1257
1299
|
|
|
1258
|
-
export default
|
|
1300
|
+
export default definePlugin({ bindings: { config: 'ConfigStore:site_config' } }, {
|
|
1259
1301
|
middleware: (app) => {
|
|
1260
1302
|
app.use('/api/*', async (c, next) => {
|
|
1261
1303
|
await next();
|
|
1262
1304
|
c.header('cache-control', 'no-store');
|
|
1263
1305
|
});
|
|
1264
1306
|
},
|
|
1265
|
-
|
|
1307
|
+
routes: (app) => {
|
|
1266
1308
|
app.get('/api/greeting', async (c) => c.json({ greeting: await c.env.config?.get('greeting') }));
|
|
1267
1309
|
},
|
|
1268
|
-
|
|
1310
|
+
afterFilesRoutes: (app) => {
|
|
1269
1311
|
app.get('/blog/:slug', (c) => c.redirect(`/archive/${c.req.param('slug')}/`, 301));
|
|
1270
1312
|
},
|
|
1271
1313
|
});
|
|
1272
1314
|
```
|
|
1273
1315
|
|
|
1274
|
-
**Options** come from `templateOptions.hono.
|
|
1316
|
+
**Options** come from `templateOptions.hono.compose.plugins` in the project file (or in `static-publish.rc.js`), with the name of the plugin as the key. Each phase of a plugin gets the same options. The build shows a warning for options of a plugin that does not exist:
|
|
1275
1317
|
|
|
1276
1318
|
```js
|
|
1277
1319
|
templateOptions: {
|
|
1278
1320
|
hono: {
|
|
1279
1321
|
bindings: { config: 'ConfigStore:site_config' },
|
|
1280
|
-
|
|
1322
|
+
compose: { plugins: { header: { value: 'my-site' } } },
|
|
1281
1323
|
},
|
|
1282
1324
|
},
|
|
1283
1325
|
```
|
|
1284
1326
|
|
|
1285
|
-
**The files step:** between `
|
|
1327
|
+
**The files step:** between `routes` and `afterFilesRoutes`, the app has a fixed step that serves the published files with `serveStatic()`. It is not a phase, and a plugin cannot remove it. A plugin can serve files in another way before it: a request that the plugin answers does not get to this step, and a request that the plugin passes on with `next()` does.
|
|
1286
1328
|
|
|
1287
|
-
**Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer` that the app uses (see [Using Hono](#-using-hono)). They are made once when the app starts, with the same `collectionSelection`, so a
|
|
1329
|
+
**Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer` that the app uses (see [Using Hono](#-using-hono)). They are made once when the app starts, with the same `collectionSelection`, so a plugin can serve published files in its own place in the order, with its own rules.
|
|
1288
1330
|
|
|
1289
|
-
For example, a
|
|
1331
|
+
For example, a plugin that runs before a login check, and serves `/theme/*` on a preview: from the selected collection, or from the default collection if the preview is missing, and with a plain `404` (not the 404 page of the collection, which would show the preview without a login). Without a preview, the plugin does nothing, and the app serves the request as usual. In Hono, a handler cannot skip the handlers that come after it in the same `app.use()`, so the plugin decides first whether it takes part. Two ways to write it, which do the same:
|
|
1290
1332
|
|
|
1291
1333
|
```ts
|
|
1292
|
-
// hono-
|
|
1293
|
-
import {
|
|
1334
|
+
// hono-compose/10-theme.ts: one handler with staticResponse()
|
|
1335
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1294
1336
|
|
|
1295
|
-
export default
|
|
1337
|
+
export default definePlugin((app, options, { staticResponse }) => {
|
|
1296
1338
|
app.use('/theme/*', async (c, next) => {
|
|
1297
1339
|
if (c.var.staticPublisher.collectionName == null) {
|
|
1298
1340
|
return next(); // not a preview: the app serves it as usual
|
|
@@ -1303,11 +1345,11 @@ export default defineExtension((app, options, { staticResponse }) => {
|
|
|
1303
1345
|
```
|
|
1304
1346
|
|
|
1305
1347
|
```ts
|
|
1306
|
-
// hono-
|
|
1307
|
-
import {
|
|
1348
|
+
// hono-compose/10-theme.ts: serveStatic() with except() of hono/combine
|
|
1349
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1308
1350
|
import { except } from 'hono/combine';
|
|
1309
1351
|
|
|
1310
|
-
export default
|
|
1352
|
+
export default definePlugin((app, options, { serveStatic }) => {
|
|
1311
1353
|
const notPreview = (c) => c.var.staticPublisher.collectionName == null;
|
|
1312
1354
|
app.use('/theme/*', except(notPreview,
|
|
1313
1355
|
serveStatic({ onMissing: 'default' }),
|
|
@@ -1320,13 +1362,13 @@ export default defineExtension((app, options, { serveStatic }) => {
|
|
|
1320
1362
|
|
|
1321
1363
|
With `onMissing: 'default'`, a missing preview gets a normal response of the default collection, with its headers. When the preview is published, the next request gets the file of the preview: `PublisherServer` checks the selected collection before it reads the response cache. These examples are for a `host`, `query`, `cookie`, or `header` source. With a `path` source, the request path has the prefix (for example `/_preview/pr-1/theme/site.css`), so the route `/theme/*` does not match it: add the handler on `*`, and check `c.var.staticPublisher.pathname`, the path without the prefix. `serveStatic()` and `staticResponse()` look up that path.
|
|
1322
1364
|
|
|
1323
|
-
For example, a
|
|
1365
|
+
For example, a plugin that runs after a login check, and shows the page `/preview-not-found/` of the default collection, with a `404`, when the selected preview is not available. Because it is a plugin, it can come after the login check, so that a visitor who is not logged in cannot learn which previews exist:
|
|
1324
1366
|
|
|
1325
1367
|
```ts
|
|
1326
|
-
// hono-
|
|
1327
|
-
import {
|
|
1368
|
+
// hono-compose/30-preview-not-found.ts
|
|
1369
|
+
import { definePlugin } from '@fastly/compute-js-static-publish/hono';
|
|
1328
1370
|
|
|
1329
|
-
export default
|
|
1371
|
+
export default definePlugin((app, options, { isCollectionAvailable, staticResponse }) => {
|
|
1330
1372
|
app.use('*', async (c, next) => {
|
|
1331
1373
|
if (await isCollectionAvailable(c)) {
|
|
1332
1374
|
return next();
|
|
@@ -1337,31 +1379,31 @@ export default defineExtension((app, options, { isCollectionAvailable, staticRes
|
|
|
1337
1379
|
});
|
|
1338
1380
|
```
|
|
1339
1381
|
|
|
1340
|
-
**`publisherServer` in a
|
|
1382
|
+
**`publisherServer` in a plugin:** the app has one `PublisherServer` for all requests. Use the other helpers where you can: they use the selected collection, and the path without the prefix of a `path` source. In a handler, a plugin can call these methods of `publisherServer`:
|
|
1341
1383
|
|
|
1342
1384
|
- `isCollectionAvailable()`, `serveRequest()`, `serveFallback()`, and `resolveCollection()`.
|
|
1343
1385
|
- The methods that read the collection of the request: `getServerConfig()`, `getStaticItems()`, `getAssetEntryMap()`, `getMatchingAsset()`, and `testExtendedCache()`. They use the collection of the last `serveRequest()` or `serveFallback()` in the request (also through `serveStatic()` and the other helpers), or of `beginRequest()`, which uses the active collection, not the selected one. If neither ran in the request, call `publisherServer.beginRequest(c.req.raw)` first.
|
|
1344
1386
|
|
|
1345
1387
|
Do not call the `set…()` methods (`setActiveCollectionName()`, `setCollectionSelection()`, `setResponseCache()`, and the others) in a handler: they change the server for all requests. In the phase function, which runs one time when the app starts, they change the configuration of the whole app. Do not call the lower-level methods (`serveAsset()`, `serveCached()`, `serveCachedStreaming()`, `loadAssetVariant()`, `handlePreconditions()`, and `findAcceptEncodingsGroups()`). Use `staticResponse()` and `fallbackResponse()` in their place.
|
|
1346
1388
|
|
|
1347
|
-
**Bindings** put Fastly resources on `c.env`, as `buildFire()` of `@fastly/hono-fastly-compute` does. A
|
|
1389
|
+
**Bindings** put Fastly resources on `c.env`, as `buildFire()` of `@fastly/hono-fastly-compute` does. A plugin declares the bindings that it uses in the first argument of `definePlugin()`, and `c.env` in its handlers has their types, for example `ConfigStore | undefined` for `'ConfigStore:site_config'` (`undefined` if the resource does not exist or is not linked to the service). `templateOptions.hono.bindings` adds bindings for the app. The same name with the same resource in two places is allowed. The same name with two different resources stops the build, and the message names both places. `c.var` is not typed in a plugin, so that a plugin can set its own variables.
|
|
1348
1390
|
|
|
1349
|
-
**Errors** in a
|
|
1391
|
+
**Errors** in a plugin stop the build, and the message names the file: a default export that is not `definePlugin()`, an object with no phase, a key that is not a phase, or a phase that is not a function.
|
|
1350
1392
|
|
|
1351
|
-
**The build** bundles the
|
|
1393
|
+
**The build** bundles the plugins into `src/hono-compose.generated.js` of the app (the `prebuild` [template hook](#-template-hooks)). The packages that the app provides stay imports, so that the app has one copy of each: the dependencies of the app (for example `hono` and `@fastly/hono-fastly-compute`), this package, and `fastly:*`. Thus, do not add them to the `dependencies` of the folder. `template init` writes them as peer dependencies in `hono-compose/package.json`, with the versions that the app has. `npm install` in `hono-compose/` installs them too, because npm 7 and later install peer dependencies. These copies are only for your editor and the type checker. The build always uses the copies of the app. Install other packages in the folder, and the build bundles them.
|
|
1352
1394
|
|
|
1353
|
-
- `build.hono.
|
|
1354
|
-
- Without the folder, or without
|
|
1355
|
-
- In a managed project, the files of the folder (without `node_modules/`) are part of the fingerprint, so a change to a
|
|
1356
|
-
- Keep the code of the
|
|
1395
|
+
- `build.hono.composeDir` sets another folder, relative to the project file (or to `static-publish.rc.js`). The default is `./hono-compose`.
|
|
1396
|
+
- Without the folder, or without plugins, the app has no plugins. `dev` and `deploy` of a managed project then show how to make the folder.
|
|
1397
|
+
- In a managed project, the files of the folder (without `node_modules/`) are part of the fingerprint, so a change to a plugin makes `deploy` deploy again.
|
|
1398
|
+
- Keep the code of the plugins in the folder. A plugin can import a file from outside the folder, and the build bundles it, but a change to that file does not change the fingerprint, and the watcher does not see it.
|
|
1357
1399
|
|
|
1358
|
-
**`template init`** makes the folder with `package.json`, `tsconfig.json`, `.gitignore` (for `node_modules/`), and the example. In a folder that exists, it updates only the peer dependencies, and adds the starter files that are missing. It never changes your
|
|
1400
|
+
**`template init`** makes the folder with `package.json`, `tsconfig.json`, `.gitignore` (for `node_modules/`), and the example. In a folder that exists, it updates only the peer dependencies, and adds the starter files that are missing. It never changes your plugins. `--reset` writes the starter files again (it asks first, or needs `--force` with `--non-interactive`). `--check` changes nothing, and fails with `template-init-needed` if the folder is out of date, for example after an upgrade of this package; use it in CI.
|
|
1359
1401
|
|
|
1360
|
-
**Watch:** `dev -- --watch` (managed) and `npm run dev:watch` (ejected) also watch the
|
|
1402
|
+
**Watch:** `dev -- --watch` (managed) and `npm run dev:watch` (ejected) also watch the folder of the plugins, also if it does not exist yet. A change in the folder bundles the plugins again, and then the Fastly CLI builds and restarts the app. If a plugin has an error, the watcher shows it and the app keeps the last plugins that built.
|
|
1361
1403
|
|
|
1362
|
-
**Examples** in [`examples/hono/`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono) show complete
|
|
1404
|
+
**Examples** in [`examples/hono/`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono) show complete plugins. They are not part of the npm package, and you cannot scaffold an app with them: for a new project, copy the `hono-compose/` folder of an example into your project, and set it up as the README of the example shows. The README also shows how to add an example to a project that exists.
|
|
1363
1405
|
|
|
1364
|
-
- [`grip`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/grip): realtime streams and Server-Sent Events with Fastly Fanout, and a publish endpoint with a shared key. One
|
|
1406
|
+
- [`grip`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/grip): realtime streams and Server-Sent Events with Fastly Fanout, and a publish endpoint with a shared key. One plugin with two phases: the `middleware` phase hands off only `/events/*` to Fanout, and the `routes` phase has the endpoints.
|
|
1365
1407
|
- [`oauth`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/oauth): a login with GitHub or Google in front of some paths of the site (`protect`), with a signed session cookie.
|
|
1366
1408
|
|
|
1367
1409
|
Each example takes its secrets from a Secret Store. For `dev`, `managed.fastlyToml` adds a local Secret Store that reads environment variables.
|
|
@@ -1635,7 +1677,7 @@ Each object has `schemaVersion` (now `1`). A new field keeps the version. A fiel
|
|
|
1635
1677
|
}
|
|
1636
1678
|
```
|
|
1637
1679
|
|
|
1638
|
-
`template.provides` lists the packages that the app of the template provides to the folder of the template (for example `hono-
|
|
1680
|
+
`template.provides` lists the packages that the app of the template provides to the folder of the template (for example `hono-compose/`), with their versions.
|
|
1639
1681
|
|
|
1640
1682
|
In an ejected app, `status --json` gives `{ "schemaVersion": 1, "mode": "ejected", "serviceId": "SERVICE_ID" }`.
|
|
1641
1683
|
|
|
@@ -1669,7 +1711,7 @@ In an ejected app, `status --json` gives `{ "schemaVersion": 1, "mode": "ejected
|
|
|
1669
1711
|
| `version-mismatch` | `2` | `managed.staticPublishVersion` is not the version of the CLI that runs |
|
|
1670
1712
|
| `first-deploy-manual` | `2` | The first deploy of a managed project with S3 storage, with `--non-interactive` |
|
|
1671
1713
|
| `version-not-published` | `2` | `eject` needs a version of this package that is on npm |
|
|
1672
|
-
| `template-init-needed` | `2` | `template init --check`: the folder of the template (for example `hono-
|
|
1714
|
+
| `template-init-needed` | `2` | `template init --check`: the folder of the template (for example `hono-compose/`) is out of date. Run `template init` |
|
|
1673
1715
|
| `deploy-failed` | `1` | The build or the deploy of the app failed |
|
|
1674
1716
|
| `failed` | `1` | The operation failed, for example storage cannot be reached |
|
|
1675
1717
|
|
|
@@ -1689,7 +1731,7 @@ npx @fastly/compute-js-static-publish@beta \
|
|
|
1689
1731
|
--root-dir=./public \
|
|
1690
1732
|
--kv-store-name=<site-content>
|
|
1691
1733
|
|
|
1692
|
-
# Using S3 storage
|
|
1734
|
+
# Using S3 storage
|
|
1693
1735
|
npx @fastly/compute-js-static-publish@beta \
|
|
1694
1736
|
--root-dir=./public \
|
|
1695
1737
|
--storage-mode=s3 \
|
|
@@ -1805,7 +1847,7 @@ npx @fastly/compute-js-static-publish@beta publish-content \
|
|
|
1805
1847
|
[--verbose]
|
|
1806
1848
|
```
|
|
1807
1849
|
|
|
1808
|
-
Publishes static files from your local root directory into a named collection, in the storage that `static-publish.rc.js` specifies: the Fastly KV Store, S3-compatible storage
|
|
1850
|
+
Publishes static files from your local root directory into a named collection, in the storage that `static-publish.rc.js` specifies: the Fastly KV Store, S3-compatible storage, or a local dev directory (`--local`, KV Store mode only).
|
|
1809
1851
|
|
|
1810
1852
|
Before it scans your files, the command lists the files that are already in storage. Files that already exist with the same hash are not compressed or uploaded again. With the KV Store, a file larger than 20 MiB is stored in chunks, and the command uploads a chunk again if the chunk in storage does not have the correct size. Then the command uploads the remaining files in batches.
|
|
1811
1853
|
|
|
@@ -1818,7 +1860,7 @@ After this process is complete, the PublisherServer object in the Compute applic
|
|
|
1818
1860
|
- `--root-dir`: Source directory to read files from (overrides value in `publish-content.config.js`)
|
|
1819
1861
|
- `--overwrite-existing`: Always upload all files, even if they are already in storage. `--kv-overwrite` is an alias.
|
|
1820
1862
|
- `--brotli-quality`: Brotli quality for the `br` variants, an integer from 0 to 11. Overrides `brotliQuality` in `publish-content.config.js`. This is useful in CI, where the config file is generated at each run.
|
|
1821
|
-
- `--fastly-service-id`: The Fastly Service ID to purge after publishing. The command purges the surrogate key `<publishId>-<collectionName>`, so that the service stops serving cached copies of the collection's settings, index,
|
|
1863
|
+
- `--fastly-service-id`: The Fastly Service ID to purge after publishing. The command purges the surrogate key `<publishId>-<collectionName>`, so that the service stops serving cached copies of the collection's settings, index, and responses (see [response cache](#️-caching-responses-with-the-core-cache)). If not set, the tool will check:
|
|
1822
1864
|
- **`FASTLY_SERVICE_ID` environment variable**
|
|
1823
1865
|
- `service_id` in `fastly.toml`
|
|
1824
1866
|
|
|
@@ -1840,7 +1882,7 @@ After this process is complete, the PublisherServer object in the Compute applic
|
|
|
1840
1882
|
|
|
1841
1883
|
- `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
|
|
1842
1884
|
|
|
1843
|
-
**S3 Storage Options
|
|
1885
|
+
**S3 Storage Options:**
|
|
1844
1886
|
|
|
1845
1887
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1846
1888
|
- `--s3-upload-concurrency`: Number of objects to upload at the same time, from 1 to 256 (default: 64). Each upload keeps its file in memory, so a site with many large files can need a lower value.
|
|
@@ -1867,7 +1909,7 @@ This can include expired collection indexes and orphaned content assets.
|
|
|
1867
1909
|
|
|
1868
1910
|
- `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
|
|
1869
1911
|
|
|
1870
|
-
**S3 Storage Options
|
|
1912
|
+
**S3 Storage Options:**
|
|
1871
1913
|
|
|
1872
1914
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1873
1915
|
|
|
@@ -1886,7 +1928,7 @@ Lists all collections currently published in storage.
|
|
|
1886
1928
|
|
|
1887
1929
|
- `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
|
|
1888
1930
|
|
|
1889
|
-
**S3 Storage Options
|
|
1931
|
+
**S3 Storage Options:**
|
|
1890
1932
|
|
|
1891
1933
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1892
1934
|
|
|
@@ -1926,7 +1968,7 @@ If a Service ID is found, the command then purges the surrogate key `<publishId>
|
|
|
1926
1968
|
- `--fastly-service-id`: The Fastly Service ID to purge after promoting. If not set, the tool checks the `FASTLY_SERVICE_ID` environment variable, then `service_id` in `fastly.toml`. If none is found, the command skips the purge. The purge also needs an API token (see `--fastly-api-token`), also in S3 mode. With `--local`, there is no purge. If the purge fails, the command shows a warning and completes, because the collection is already promoted.
|
|
1927
1969
|
- `--purge-environment`: The environments to purge: `production` (the default), `staging`, or both, as a comma-separated list. You can also repeat the option.
|
|
1928
1970
|
|
|
1929
|
-
**S3 Storage Options
|
|
1971
|
+
**S3 Storage Options:**
|
|
1930
1972
|
|
|
1931
1973
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1932
1974
|
|
|
@@ -1956,7 +1998,7 @@ Sets or updates the expiration time of an existing collection.
|
|
|
1956
1998
|
|
|
1957
1999
|
- `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
|
|
1958
2000
|
|
|
1959
|
-
**S3 Storage Options
|
|
2001
|
+
**S3 Storage Options:**
|
|
1960
2002
|
|
|
1961
2003
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1962
2004
|
|
|
@@ -1987,7 +2029,7 @@ If a Service ID is found, the command then purges the surrogate key `<publishId>
|
|
|
1987
2029
|
|
|
1988
2030
|
- `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
|
|
1989
2031
|
|
|
1990
|
-
**S3 Storage Options
|
|
2032
|
+
**S3 Storage Options:**
|
|
1991
2033
|
|
|
1992
2034
|
- `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
|
|
1993
2035
|
|
package/MIGRATING.md
CHANGED
|
@@ -17,7 +17,7 @@ changing the version of this package. See "Managed and ejected apps" in `README.
|
|
|
17
17
|
|
|
18
18
|
> [!IMPORTANT]
|
|
19
19
|
> Managed mode generates the app from a template: `plain` (the default) or `hono`. If you changed `src/index.js` (or
|
|
20
|
-
> other files of the app), move your changes into options of the project file, or into
|
|
20
|
+
> other files of the app), move your changes into options of the project file, or into plugin modules (see
|
|
21
21
|
> [An app with changes to `src/index.js`](#an-app-with-changes-to-srcindexjs)), or keep your app ejected.
|
|
22
22
|
|
|
23
23
|
These steps move a project with this layout. Change the paths to match your project:
|
|
@@ -103,24 +103,24 @@ my-site/
|
|
|
103
103
|
### An app with changes to `src/index.js`
|
|
104
104
|
|
|
105
105
|
Managed mode generates `src/index.js` again for each build, so your changes to it would be lost. With the `hono`
|
|
106
|
-
template, you can keep your code in
|
|
107
|
-
The build bundles them into the app. Code that ran before `serveRequest()`, for example a redirect of an old
|
|
108
|
-
a login check, or a proxy to another service, goes into a `middleware` or `
|
|
109
|
-
file matched, for example a special page for a path, goes into an `
|
|
110
|
-
and declares the Fastly resources that it uses (bindings).
|
|
106
|
+
template, you can keep your code in plugin modules: files in the folder `hono-compose/`, beside the
|
|
107
|
+
project file. The build bundles them into the app. Code that ran before `serveRequest()`, for example a redirect of an old
|
|
108
|
+
host name, a login check, or a proxy to another service, goes into a `middleware` or `routes` phase. Code that ran when no
|
|
109
|
+
file matched, for example a special page for a path, goes into an `afterFilesRoutes` phase. Each plugin gets its own
|
|
110
|
+
options, and declares the Fastly resources that it uses (bindings).
|
|
111
111
|
|
|
112
112
|
1. In step 2, add `template: "hono"` to `managed`.
|
|
113
113
|
2. In `my-site/`, make the folder, and install its packages:
|
|
114
114
|
|
|
115
115
|
```sh
|
|
116
116
|
npx compute-js-static-publish template init
|
|
117
|
-
cd hono-
|
|
117
|
+
cd hono-compose
|
|
118
118
|
npm install
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
3. Move each part of your code into a
|
|
122
|
-
the bindings, and `examples/hono/` in the repository for two complete examples.
|
|
123
|
-
4. Continue with step 3 above. `dev` and `deploy` build the app with your
|
|
121
|
+
3. Move each part of your code into a plugin. See "Composing plugin modules" in `README.md` for the phases, the options,
|
|
122
|
+
and the bindings, and `examples/hono/` in the repository for two complete examples.
|
|
123
|
+
4. Continue with step 3 above. `dev` and `deploy` build the app with your plugins.
|
|
124
124
|
|
|
125
125
|
## Move from `@fastly/hono-compute-js-static-publish` (8.1)
|
|
126
126
|
|
|
@@ -160,6 +160,39 @@ Differences of `serveStatic()`:
|
|
|
160
160
|
- It serves only `GET` and `HEAD`. For other methods, it calls the next handler.
|
|
161
161
|
- For previews, use `selectCollection()` with `collectionSelection` in `static-publish.rc.js` (see [Using Hono](./README.md#-using-hono)).
|
|
162
162
|
|
|
163
|
+
## Update the plugins from an earlier beta of 8.1
|
|
164
|
+
|
|
165
|
+
In the betas of 8.1 before 8.1.0-beta.9, plugin modules had other names ("Hono extensions"). Your plugins
|
|
166
|
+
work the same way; only the names change. Each old name stops the build, and the message gives the new name.
|
|
167
|
+
|
|
168
|
+
| Before | Now |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| The folder `hono-extensions/` | `hono-compose/` |
|
|
171
|
+
| `defineExtension()` (from `@fastly/compute-js-static-publish/hono`) | `definePlugin()` (the same import) |
|
|
172
|
+
| The phase `beforeFiles` or `beforeFilesRoutes` | `routes` |
|
|
173
|
+
| The phase `afterFiles` | `afterFilesRoutes` |
|
|
174
|
+
| The types `ExtensionEnv`, `ExtensionBindings`, `ExtensionPhaseFunction`, `ExtensionHelpers`, `ExtensionEntry` | `PluginEnv`, `PluginBindings`, `PluginPhaseFunction`, `PluginHelpers`, `PluginEntry` |
|
|
175
|
+
| `templateOptions.hono.extensions` | `templateOptions.hono.compose.plugins` |
|
|
176
|
+
| `build.hono.extensionsDir` | `build.hono.composeDir` |
|
|
177
|
+
|
|
178
|
+
1. Rename the folder: `git mv hono-extensions hono-compose` (in the directory of the project file, or next to
|
|
179
|
+
`compute-js/`).
|
|
180
|
+
2. In each plugin, change `defineExtension` to `definePlugin`, and the phase names and the types as the table shows.
|
|
181
|
+
3. In the project file (or in `static-publish.rc.js`), change the keys as the table shows.
|
|
182
|
+
4. In an ejected app, also update the files of the app, because nothing generates them again:
|
|
183
|
+
- `scripts/template_prebuild.js`, `scripts/template_postinstall.js`, and `scripts/template_watch.js`: the functions
|
|
184
|
+
of `@fastly/compute-js-static-publish/hono/build` are now `bundlePlugins()`, `writePluginsStub()`, and
|
|
185
|
+
`watchPlugins()`, and the constant is `PLUGINS_MANIFEST`;
|
|
186
|
+
- `src/index.ts`: import `plugins` from `./hono-compose.generated.js`, run the phase `routes` in place of
|
|
187
|
+
`beforeFilesRoutes`, read the options from `honoOptions?.compose?.plugins`, and use `p.plugin.phases` in place of
|
|
188
|
+
`e.module.phases`;
|
|
189
|
+
- `src/hono-extensions.generated.d.ts` becomes `src/hono-compose.generated.d.ts` (with `plugins: PluginEntry[]`),
|
|
190
|
+
and `.gitignore` ignores `/src/hono-compose.generated.js`.
|
|
191
|
+
|
|
192
|
+
To see the new files, scaffold a new app with `--template hono` and compare.
|
|
193
|
+
|
|
194
|
+
A managed project gets the new files of the app at the next `dev` or `deploy`.
|
|
195
|
+
|
|
163
196
|
## Upgrade from v7 to v8
|
|
164
197
|
|
|
165
198
|
v8 can use the files that v7 published. The storage key layout did not change. v8 also accepts the v7 format of
|
|
@@ -261,7 +294,7 @@ To stop using `publicDirPrefix`:
|
|
|
261
294
|
publish it again. The keys of the files are the hashes of the content, so the CLI does not upload the same files
|
|
262
295
|
again.
|
|
263
296
|
|
|
264
|
-
### Move from the KV Store to S3-compatible storage
|
|
297
|
+
### Move from the KV Store to S3-compatible storage
|
|
265
298
|
|
|
266
299
|
You do not have to move to S3-compatible storage. The KV Store continues to be the default storage mode.
|
|
267
300
|
|
|
@@ -274,7 +307,7 @@ Thus, to move, you publish your content again into the bucket:
|
|
|
274
307
|
2. Copy your changes from your current app into the new app, for example the changes to `src/index.js` and to
|
|
275
308
|
`publish-content.config.js`. Keep the same `publishId` and `defaultCollectionName`.
|
|
276
309
|
|
|
277
|
-
3. Set up the S3 credentials for publishing and for the server. See "Using S3 Compatible Storage
|
|
310
|
+
3. Set up the S3 credentials for publishing and for the server. See "Using S3 Compatible Storage" in
|
|
278
311
|
`README.md`.
|
|
279
312
|
|
|
280
313
|
4. Publish each collection that you need again, from its source files. The collections that are in the KV Store
|
|
@@ -284,6 +317,3 @@ Thus, to move, you publish your content again into the bucket:
|
|
|
284
317
|
|
|
285
318
|
6. When you do not need the KV Store content, delete it. Before you do this, make sure that no service version
|
|
286
319
|
that is active or staged uses that KV Store.
|
|
287
|
-
|
|
288
|
-
> [!NOTE]
|
|
289
|
-
> S3-compatible storage is in beta. The configuration and these steps can change before this feature is stable.
|