@adobe/helix-html-pipeline 3.11.7 → 3.11.8
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 +7 -0
- package/package.json +1 -1
- package/src/html-pipe.js +18 -1
- package/src/steps/fetch-404.js +42 -0
- package/src/steps/fetch-content.js +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.11.8](https://github.com/adobe/helix-html-pipeline/compare/v3.11.7...v3.11.8) (2023-05-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* don't load 404.html too early ([#318](https://github.com/adobe/helix-html-pipeline/issues/318)) ([6fa9f12](https://github.com/adobe/helix-html-pipeline/commit/6fa9f120eed6daca3f006062cb2f81f96708a5db))
|
|
7
|
+
|
|
1
8
|
## [3.11.7](https://github.com/adobe/helix-html-pipeline/compare/v3.11.6...v3.11.7) (2023-05-22)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/html-pipe.js
CHANGED
|
@@ -17,6 +17,7 @@ import createPictures from './steps/create-pictures.js';
|
|
|
17
17
|
import extractMetaData from './steps/extract-metadata.js';
|
|
18
18
|
import fetchConfig from './steps/fetch-config.js';
|
|
19
19
|
import fetchContent from './steps/fetch-content.js';
|
|
20
|
+
import fetch404 from './steps/fetch-404.js';
|
|
20
21
|
import fetchConfigAll from './steps/fetch-config-all.js';
|
|
21
22
|
import fixSections from './steps/fix-sections.js';
|
|
22
23
|
import folderMapping from './steps/folder-mapping.js';
|
|
@@ -39,6 +40,20 @@ import { validatePathInfo } from './utils/path.js';
|
|
|
39
40
|
import { initAuthRoute } from './utils/auth.js';
|
|
40
41
|
import fetchMappedMetadata from './steps/fetch-mapped-metadata.js';
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Fetches the content and if not found, fetches the 404.html
|
|
45
|
+
* @param state
|
|
46
|
+
* @param req
|
|
47
|
+
* @param res
|
|
48
|
+
* @returns {Promise<void>}
|
|
49
|
+
*/
|
|
50
|
+
async function fetchContentWith404Fallback(state, req, res) {
|
|
51
|
+
await fetchContent(state, req, res);
|
|
52
|
+
if (res.status === 404) {
|
|
53
|
+
await fetch404(state, req, res);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
/**
|
|
43
58
|
* Runs the default pipeline and returns the response.
|
|
44
59
|
* @param {PipelineState} state
|
|
@@ -88,7 +103,9 @@ export async function htmlPipe(state, req) {
|
|
|
88
103
|
if (res.status === 404) {
|
|
89
104
|
await folderMapping(state);
|
|
90
105
|
if (state.info.unmappedPath) {
|
|
91
|
-
contentPromise =
|
|
106
|
+
contentPromise = fetchContentWith404Fallback(state, req, res);
|
|
107
|
+
} else {
|
|
108
|
+
contentPromise = fetch404(state, req, res);
|
|
92
109
|
}
|
|
93
110
|
}
|
|
94
111
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { computeSurrogateKey } from '@adobe/helix-shared-utils';
|
|
13
|
+
import { extractLastModified } from '../utils/last-modified.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Loads the 404.html from code-bus and stores it in `res.body`
|
|
17
|
+
* @type PipelineStep
|
|
18
|
+
* @param {PipelineState} state
|
|
19
|
+
* @param {PipelineRequest} req
|
|
20
|
+
* @param {PipelineResponse} res
|
|
21
|
+
* @returns {Promise<void>}
|
|
22
|
+
*/
|
|
23
|
+
export default async function fetch404(state, req, res) {
|
|
24
|
+
const {
|
|
25
|
+
contentBusId, info, owner, repo, ref,
|
|
26
|
+
} = state;
|
|
27
|
+
const ret = await state.s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}/404.html`);
|
|
28
|
+
if (ret.status === 200) {
|
|
29
|
+
// override last-modified if source-last-modified is set
|
|
30
|
+
const lastModified = extractLastModified(ret.headers);
|
|
31
|
+
if (lastModified) {
|
|
32
|
+
ret.headers.set('last-modified', lastModified);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// keep 404 response status
|
|
36
|
+
res.body = ret.body;
|
|
37
|
+
res.headers.set('last-modified', ret.headers.get('last-modified'));
|
|
38
|
+
res.headers.set('content-type', 'text/html; charset=utf-8');
|
|
39
|
+
const pathKey = await computeSurrogateKey(`${contentBusId}${info.path}`);
|
|
40
|
+
res.headers.set('x-surrogate-key', `${pathKey} ${ref}--${repo}--${owner}_404`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -69,23 +69,4 @@ export default async function fetchContent(state, req, res) {
|
|
|
69
69
|
res.status = ret.status === 404 ? 404 : 502;
|
|
70
70
|
res.error = `failed to load ${info.resourcePath} from ${state.content.sourceBus}-bus: ${ret.status}`;
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
if (res.status === 404) {
|
|
74
|
-
// try to load 404.html from code-bus
|
|
75
|
-
const ret404 = await state.s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}/404.html`);
|
|
76
|
-
if (ret404.status === 200) {
|
|
77
|
-
// override last-modified if source-last-modified is set
|
|
78
|
-
const lastModified = extractLastModified(ret404.headers);
|
|
79
|
-
if (lastModified) {
|
|
80
|
-
ret404.headers.set('last-modified', lastModified);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// keep 404 response status
|
|
84
|
-
res.body = ret404.body;
|
|
85
|
-
res.headers.set('last-modified', ret404.headers.get('last-modified'));
|
|
86
|
-
res.headers.set('content-type', 'text/html; charset=utf-8');
|
|
87
|
-
const pathKey = await computeSurrogateKey(`${contentBusId}${info.path}`);
|
|
88
|
-
res.headers.set('x-surrogate-key', `${pathKey} ${ref}--${repo}--${owner}_404`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
72
|
}
|