@fastly/compute-js-static-publish 8.0.0 → 8.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.
@@ -42,6 +42,8 @@ function requestAcceptsTextHtml(req) {
42
42
  }
43
43
  export class PublisherServer {
44
44
  constructor(publishId, storageProvider, defaultCollectionName) {
45
+ // When true, serveCached() does not store the response of the current request.
46
+ this.doNotStoreResponse = false;
45
47
  this.publishId = publishId;
46
48
  this.storageProvider = storageProvider;
47
49
  this.defaultCollectionName = defaultCollectionName;
@@ -87,6 +89,7 @@ export class PublisherServer {
87
89
  beginRequest(request) {
88
90
  this.settingsCached = undefined;
89
91
  this.assetEntryMapCache = undefined;
92
+ this.doNotStoreResponse = false;
90
93
  const header = this.serverTimingRequestHeader;
91
94
  this.serverTiming = header != null && request.headers.has(header) ? new ServerTiming() : null;
92
95
  }
@@ -450,6 +453,10 @@ export class PublisherServer {
450
453
  entry.cancel();
451
454
  throw err;
452
455
  }
456
+ if (this.doNotStoreResponse) {
457
+ entry.cancel();
458
+ return response;
459
+ }
453
460
  const insertOptions = {
454
461
  // The Core Cache takes maxAge in milliseconds. ResponseCacheOptions.maxAge is in seconds.
455
462
  maxAge: this.responseCache.maxAge * 1000,
@@ -545,7 +552,7 @@ export class PublisherServer {
545
552
  }
546
553
  async serveRequestFromStorage(request, pathname) {
547
554
  const serverConfig = await this.getServerConfig();
548
- if (serverConfig == null) {
555
+ if (serverConfig == null && this.activeCollectionName === this.defaultCollectionName) {
549
556
  return new Response(`Settings not found. You may need to publish your application.`, {
550
557
  status: 500,
551
558
  headers: {
@@ -553,6 +560,21 @@ export class PublisherServer {
553
560
  },
554
561
  });
555
562
  }
563
+ // A collection other than the default collection that is not published, or
564
+ // that expired, gets a 404. It can be published at any time, so the
565
+ // response cache does not store this response.
566
+ if (serverConfig == null ||
567
+ (this.activeCollectionName !== this.defaultCollectionName && await this.getAssetEntryMap() == null)) {
568
+ this.doNotStoreResponse = true;
569
+ return new Response(`Collection '${this.activeCollectionName}' is not available. It is not published, or it expired.`, {
570
+ status: 404,
571
+ headers: {
572
+ 'content-type': 'text/plain',
573
+ 'x-content-type-options': 'nosniff',
574
+ 'cache-control': 'no-store',
575
+ },
576
+ });
577
+ }
556
578
  const asset = await this.getMatchingAsset(serverConfig.publicDirPrefix + pathname, true);
557
579
  if (asset != null) {
558
580
  return this.serveAsset(request, asset, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.0.0",
4
+ "version": "8.0.1",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/server/server/index.js",
7
7
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "compile:server": "tsc -p tsconfig.server.json",
20
20
  "test": "npm run build && node --test \"test/unit/*.test.js\"",
21
21
  "test:e2e": "npm run build && node --test --test-concurrency=1 \"test/e2e/*.test.js\"",
22
- "prepublishOnly": "cp README.short.md README.md"
22
+ "prepublishOnly": "cp README.md DOCUMENTATION.md && cp README.short.md README.md"
23
23
  },
24
24
  "bin": {
25
25
  "compute-js-static-publish": "build/cli/cli/index.js"
@@ -68,6 +68,7 @@
68
68
  "LICENSE",
69
69
  "package.json",
70
70
  "README.md",
71
+ "DOCUMENTATION.md",
71
72
  "SECURITY.md"
72
73
  ]
73
74
  }