fix: properly serve .plain.html requests for documents in local content directory#2733
Conversation
… fixture Parse the full HTML document and return only the innerHTML of <main> rather than sending the raw file content. Uses existing hast-util-select and hast-util-to-html deps. Test fixture updated to use a realistic full document and a multiline fragment string for readability. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This PR will trigger a patch release when merged. |
…hast Remove inner try/catch in favor of upfront path rewriting — .plain.html is a virtual URL convention and AEM never stores such files in content/. Extract <main> innerHTML using hast-util-select/to-html (already transitive deps) rather than sending the raw file. Update test fixture to use a realistic full HTML document and tighten assertion to strictEqual. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| let htmlContent = await readFile(contentFilePath, 'utf-8'); | ||
| // .plain.html is a virtual URL convention — AEM never stores .plain.html files, | ||
| // so always read the corresponding .html file and serve the <main> fragment. | ||
| const isPlainFallback = contentFilePath.endsWith('.plain.html'); |
There was a problem hiding this comment.
worth noting that this assumes there will never be a .plain.html file in the content checkout directory. If that assumption doesn't hold, then this will need to be adapted to handle that case.
Run npm install to restore @adobe/helix-shared-process-queue and xdg-basedir that were in package.json but absent from node_modules. Expand single-line if in extractMainContent to satisfy the curly and max-statements-per-line ESLint rules. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| * @param {string} html full HTML document | ||
| * @returns {string} innerHTML of <main>, or original html if no <main> present | ||
| */ | ||
| extractMainContent(html) { |
| res.set({ | ||
| 'content-type': 'text/html; charset=utf-8', | ||
| 'access-control-allow-origin': '*', | ||
| }); |
There was a problem hiding this comment.
why is access-control-allow-origin needed ? this is not happening in prod...
There was a problem hiding this comment.
It looks to me like we are setting access-control-allow-origin: * on all responses from the local dev server, originally added in #1900. so this just follows that same pattern as all other locally-served responses in this handler (lines 512, 521, 541, 551).
Adds tests for the normal case, empty <main>, no <main> fallback, nested markup, and whitespace-only content. Also removes a redundant inline comment made obvious by the function name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🎉 This PR is included in version 16.19.12 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fix: #2732
Please ensure your pull request adheres to the following guidelines:
Related Issues
Thanks for contributing!