You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`kvStoreName` - The name of the KV Store used for publishing (required).
127
-
-`defaultCollectionName` - Collection to serve when none is specified (required).
128
-
-`publishId` - Unique prefix for all keys in the KV Store (required). Override only for advanced setups (e.g., multiple apps sharing the same KV Store).
127
+
All fields are required.
128
+
129
+
-`kvStoreName` - The name of the KV Store used for publishing.
130
+
-`defaultCollectionName` - Collection to serve when none is specified.
131
+
-`publishId` - Unique prefix for all keys in the KV Store. Override only for advanced setups (e.g., multiple apps sharing the same KV Store).
132
+
-`staticPublisherWorkingDir` - Directory to hold working files during publish.
129
133
130
134
> [!NOTE]
131
135
> Changes to this file require rebuilding the Compute app, since a copy of it is baked into the Wasm binary.
132
136
133
-
## 🧾 Default Server Config: `publish-content.config.js`
137
+
## 🧾 Publish and Server Config: `publish-content.config.js`
134
138
135
139
This file is included as part of the scaffolding. Every time you publish content, the publish settings in this file are used for publishing the content, and the server settings are taken from this file and saved as the settings used by the server for that collection.
136
140
137
-
You can override this file for a single `publish-content` command by specifying an alternative using `--config` on the command line.
138
-
139
141
```js
140
142
constconfig= {
141
143
// these paths are relative to compute-js dir
142
144
rootDir:'../public',
143
-
staticPublisherWorkingDir:'./static-publisher',
144
145
145
146
// Include/exclude filters (optional):
146
147
excludeDirs: ['node_modules'],
@@ -175,13 +176,11 @@ const config = {
175
176
exportdefaultconfig;
176
177
```
177
178
178
-
> [!NOTE]
179
-
> Changes to this file apply when content is published.
179
+
You can override this file for a single `publish-content` command by specifying an alternative using `--config` on the command line.
180
180
181
181
### Fields:
182
182
183
183
-`rootDir` - Directory to scan for content, relative to this file (required).
184
-
-`staticPublisherWorkingDir` - Directory to hold working files during publish (default: `'./static-publisher'`).
185
184
-`excludeDirs` - Array of directory names or regex patterns to exclude (default: `['./node_modules']`).
186
185
-`excludeDotFiles` - Exclude dotfiles and dot-named directories (default: true).
187
186
-`includeWellKnown` - Always include `.well-known` even if dotfiles are excluded (default: true).
@@ -225,18 +224,19 @@ You can overwrite or republish any collection at any time. Old file hashes will
225
224
226
225
Collections can expire automatically:
227
226
228
-
- Expired collections return 404s
229
-
-They’re ignored by the server
230
-
-Their files are cleaned up by `clean`
227
+
- Expired collections are ignored by the server and return 404s
228
+
-Expiration limits can be modified (shortened, extended, reenstated) using `collections update-expiration`
229
+
-They are cleaned up by `clean --delete-expired-collections`
231
230
232
231
```sh
233
232
--expires-in=3d # relative (e.g. 1h, 2d, 1w)
234
233
--expires-at=2025-05-01T12:00Z # absolute (ISO 8601)
234
+
--expires-never
235
235
```
236
236
237
237
### Switching the active collection
238
238
239
-
By default, the app serves from the collection named in `static-publish
239
+
By default, the server app serves assets from the "default collection", named in `static-publish
240
240
.rc.js` under `defaultCollectionName`. To switch the active collection, you add custom code to your Compute app that calls `publisherServer.setActiveCollectionName(name)`:
This copies all content and server settings from the `staging` collection to the collection named in your `defaultCollectionName`. To copy to a different name, add `--to=some-other-name`.
311
+
This copies all content and server settings from the `staging` collection to `live`.
During development, starting the local preview server (`npm run start`) will run `publish-content --local-only` automatically via a `prestart hook`. This simulates publishing by writing to `kvstore.json` instead of uploading to the actual KV Store. You can preview your site at `http://127.0.0.1:7676` - no Fastly account or service required.
327
+
### Local development
328
+
329
+
During development, the local preview server (`npm run dev:start`) will run against assets loaded into the simulated KV Store provided by the local development environment.
330
+
331
+
Prior to starting the server, publish the content to the simulated KV Store:
332
+
333
+
```sh
334
+
npm run dev:publish # 'publish' your files to the simulated local KV Store
335
+
npm run dev:start # preview locally
336
+
```
337
+
338
+
This simulates publishing by writing to `kvstore.json` instead of uploading to the actual KV Store. You can preview your site at `http://127.0.0.1:7676` - no Fastly account or service required.
339
+
340
+
Note that for local development, you will have to stop and restart the local development server each time you publish updates to your content.
341
+
342
+
To publish to an alternative collection name, use:
343
+
344
+
```sh
345
+
npm run dev:publish -- --collection-name=preview-123
346
+
```
347
+
348
+
### Production
325
349
326
350
When you're ready for production:
327
351
328
352
1. [Create a free Fastly account](https://www.fastly.com/signup/?tier=free) if you haven't already.
329
-
2. Run `npm run publish-service`
353
+
2. Run `npm run fastly:deploy`
330
354
- This builds your Compute app into a Wasm binary
331
355
- Deploys it to a newor existing Fastly Compute service
332
356
- If creating a newservice:
@@ -336,7 +360,7 @@ When you're ready for production:
336
360
Once deployed, publish content like so:
337
361
338
362
```sh
339
-
npm run publish-content
363
+
npm run fastly:publish
340
364
```
341
365
342
366
This:
@@ -348,7 +372,7 @@ This:
348
372
> [!TIP]
349
373
> Upload to a specific collection by specifying the collection name when publishing content:
350
374
> ```sh
351
-
> npm run publish-content -- --collection-name=preview-42
375
+
> npm run fastly:publish -- --collection-name=preview-42
352
376
> ```
353
377
354
378
**No Wasm redeploy needed** unless you:
@@ -359,14 +383,25 @@ This:
359
383
If you do need to rebuild and redeploy the Compute app, simply run:
360
384
361
385
```sh
362
-
npm run publish-service
386
+
npm run dev:deploy
363
387
```
364
388
365
389
## 🧹 Cleaning Up
366
390
367
-
Every time you publish, old files are left behind for safety. **However, files with the same content will be re-used across collections and publishing events** - they are only stored once in the KV Store using their content hash as a key. This ensures that unchanged files aren't duplicated, keeping storage efficient and deduplicated. To avoid bloat, use:
391
+
Every time you publish, old files are left behind for safety. **However, files with the same content will be re-used across collections and publishing events.** They are only stored once in the KV Store using their content hash as a key. This ensures that unchanged files aren't duplicated, keeping storage efficient and deduplicated.
392
+
393
+
Over time, however, collections may expire, old versions of files will be left behind, and some assets in the KV Store will no longer be referenced by any live collection. To avoid bloat, use:
368
394
369
395
```sh
396
+
npm run dev:clean
397
+
```
398
+
and
399
+
```sh
400
+
npm run fastly:clean
401
+
```
402
+
403
+
These scripts run against the local and Fastly KV Stores respectively, and run the following command:
| activatePath (default `/activate`) | Set the cookie | `collection` (required) - name of the collection<br /> `redirectTo` (optional, `/` by default) | `302` redirect with a `Set-Cookie` header |
714
+
| resetPath (default `/reset`) | Clear the cookie | `redirectTo` (optional, `/` by default) | `302` redirect that expires the cookie |
715
+
716
+
If a visitor accesses `/activate?collection=blue&redirectTo=/preview`, the helper will issue a redirect and drop `publisher-collection=blue` into their cookie jar.
717
+
- If someone forgets `?collection=?`? Then `/activate` replies with HTTP `400`.
718
+
719
+
When the visitor hits `/reset`, the cookie is deleted.
720
+
721
+
3. Safety flags are baked in
722
+
723
+
- `HttpOnly` is on by default (configurable), to help avoid XSS issues.
724
+
- `Secure` is automatically added on HTTPS requests.
725
+
- `SameSite=Lax` is always set – reasonable default for previews.
0 commit comments