Skip to content

Commit c0bb56e

Browse files
dvdksnclaude
andcommitted
Fix homepage markdown content negotiation
The CloudFront Lambda rewrote `/` with `Accept: text/markdown` to an invalid `.md` URI, causing a 502 LambdaValidationError. Homepage has no flattened markdown equivalent, so route to `/llms.txt` — the agent-oriented markdown index of the site. Same handling for `/index.html`. Also set `Content-Type: text/markdown` on `llms.txt` at upload time, so content negotiation responses and direct requests both advertise the correct media type. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f90b2db commit c0bb56e

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ jobs:
103103
--exclude "*" \
104104
--include "*.pf_meta" \
105105
--include "*.pf_fragment"
106+
-
107+
name: Set markdown Content-Type on llms.txt
108+
if: ${{ env.DOCS_S3_BUCKET != '' }}
109+
run: |
110+
aws --region ${{ env.DOCS_AWS_REGION }} s3 cp \
111+
s3://${{ env.DOCS_S3_BUCKET }}/llms.txt \
112+
s3://${{ env.DOCS_S3_BUCKET }}/llms.txt \
113+
--content-type="text/markdown" \
114+
--metadata-directive="REPLACE"
106115
-
107116
name: Update Cloudfront config
108117
if: ${{ env.DOCS_CLOUDFRONT_ID != '' }}

hack/releaser/cloudfront-lambda-redirects.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ exports.handler = (event, context, callback) => {
6868
// If it's not a file, treat it as a directory
6969
if (!hasFileExtension) {
7070
if (wantsMarkdown) {
71-
// Markdown files are flattened: /path/to/page.md not /path/to/page/index.md
72-
uri = uri.replace(/\/$/, '') + '.md';
71+
// Markdown files are flattened: /path/to/page.md not /path/to/page/index.md.
72+
// Homepage has no flattened equivalent, so serve llms.txt as the
73+
// agent-oriented markdown index of the site.
74+
const stripped = uri.replace(/\/$/, '');
75+
uri = stripped === '' ? '/llms.txt' : stripped + '.md';
7376
} else {
7477
// HTML uses directory structure with index.html
7578
if (!uri.endsWith("/")) {
@@ -79,8 +82,9 @@ exports.handler = (event, context, callback) => {
7982
}
8083
request.uri = uri;
8184
} else if (wantsMarkdown && uri.endsWith('/index.html')) {
82-
// If requesting index.html but wants markdown, use the flattened .md file
83-
uri = uri.replace(/\/index\.html$/, '.md');
85+
// If requesting index.html but wants markdown, use the flattened .md file.
86+
// Root index.html has no flattened equivalent, so serve llms.txt instead.
87+
uri = uri === '/index.html' ? '/llms.txt' : uri.replace(/\/index\.html$/, '.md');
8488
request.uri = uri;
8589
}
8690

0 commit comments

Comments
 (0)