@adobe/helix-html-pipeline 5.4.1 → 5.4.3

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.4.3](https://github.com/adobe/helix-html-pipeline/compare/v5.4.2...v5.4.3) (2023-12-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency mime to v4.0.1 ([54c556d](https://github.com/adobe/helix-html-pipeline/commit/54c556dca14d7860ac774cd8bc9a5bbdc626005f))
7
+
8
+ ## [5.4.2](https://github.com/adobe/helix-html-pipeline/compare/v5.4.1...v5.4.2) (2023-12-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * handle redirects correctly for static .html ([#476](https://github.com/adobe/helix-html-pipeline/issues/476)) ([5fd99d7](https://github.com/adobe/helix-html-pipeline/commit/5fd99d798076ba6d693fbf70a24ce5d1290fc9de))
14
+
1
15
  ## [5.4.1](https://github.com/adobe/helix-html-pipeline/compare/v5.4.0...v5.4.1) (2023-12-19)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "5.4.1",
3
+ "version": "5.4.3",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -56,7 +56,7 @@
56
56
  "jose": "5.1.3",
57
57
  "mdast-util-to-hast": "13.0.2",
58
58
  "mdast-util-to-string": "4.0.0",
59
- "mime": "4.0.0",
59
+ "mime": "4.0.1",
60
60
  "rehype-format": "5.0.0",
61
61
  "rehype-parse": "9.0.0",
62
62
  "remark-parse": "11.0.0",
package/src/html-pipe.js CHANGED
@@ -54,6 +54,31 @@ async function fetchContentWith404Fallback(state, req, res) {
54
54
  }
55
55
  }
56
56
 
57
+ /**
58
+ * Loads the resource from the content bus but only handles the redirect; otherwise applies
59
+ * a 404 fallback.
60
+ * @param state
61
+ * @param req
62
+ * @param res
63
+ * @returns {Promise<void>}
64
+ */
65
+ async function fetchContentRedirectWith404Fallback(state, req, res) {
66
+ // force load from content bus again
67
+ state.content.sourceBus = 'content';
68
+ const prevError = res.error;
69
+ try {
70
+ await fetchContent(state, req, res);
71
+ } finally {
72
+ state.content.sourceBus = 'code';
73
+ }
74
+ if (res.status !== 301) {
75
+ // force 404
76
+ res.status = 404;
77
+ res.error = prevError;
78
+ await fetch404(state, req, res);
79
+ }
80
+ }
81
+
57
82
  /**
58
83
  * Runs the default pipeline and returns the response.
59
84
  * @param {PipelineState} state
@@ -104,13 +129,18 @@ export async function htmlPipe(state, req) {
104
129
  // ...and apply the folder mapping
105
130
  state.timer?.update('content-fetch');
106
131
  let contentPromise = await fetchContent(state, req, res);
107
- // ...but only if the current resource doesn't exist
108
132
  if (res.status === 404) {
109
- await folderMapping(state);
110
- if (state.info.unmappedPath) {
111
- contentPromise = fetchContentWith404Fallback(state, req, res);
133
+ // special handling for code-bus 404
134
+ if (state.content.sourceBus === 'code') {
135
+ contentPromise = fetchContentRedirectWith404Fallback(state, req, res);
112
136
  } else {
113
- contentPromise = fetch404(state, req, res);
137
+ // ...apply folder mapping if the current resource doesn't exist
138
+ await folderMapping(state);
139
+ if (state.info.unmappedPath) {
140
+ contentPromise = fetchContentWith404Fallback(state, req, res);
141
+ } else {
142
+ contentPromise = fetch404(state, req, res);
143
+ }
114
144
  }
115
145
  }
116
146