fix: enable markdown negotiation for agents#288
Open
GalvinGao wants to merge 2 commits into
Open
Conversation
Changed Files
|
Preview Deployment
|
There was a problem hiding this comment.
Pull request overview
This PR updates the TanStack Start Cloudflare worker to properly negotiate Accept: text/markdown requests (so Cloudflare can convert HTML → Markdown for Agents), while keeping normal browser requests rendering HTML by default. It also adds release automation to enable Cloudflare’s content_converter setting and verify that /search returns text/markdown for markdown requests.
Changes:
- Add markdown accept-detection + normalization and ensure responses vary on
Acceptfor markdown requests. - Switch the worker/server entry configuration to point at the app’s server entry and configure TanStack Start’s server entry accordingly.
- Add a Cloudflare API script + release workflow steps to enable and verify “Markdown for Agents”.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/web/wrangler.jsonc | Switch worker main entry to the project’s server entry. |
| apps/web/vite.config.ts | Configure TanStack Start to use a custom server entry. |
| apps/web/src/start.ts | Add request middleware to normalize markdown Accept and add Vary: Accept. |
| apps/web/src/setup/markdownNegotiation.ts | Implement markdown Accept detection and normalization helper. |
| apps/web/src/setup/tests/markdownNegotiation.test.ts | Add unit tests for markdown detection/normalization helpers. |
| apps/web/src/server.ts | Normalize markdown Accept before SSR and add Vary: Accept when applicable. |
| apps/web/scripts/cloudflare-markdown-for-agents.mjs | Add script to enable/verify Cloudflare Markdown for Agents via API + HTTP check. |
| apps/web/package.json | Add npm scripts for enabling/verifying Markdown for Agents. |
| .github/workflows/release.yml | Enable Cloudflare content_converter post-deploy and verify markdown response. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agents requesting
Accept: text/markdownno longer hit TanStack Start's HTML-only request guard before Cloudflare can convert the response. Browser requests still render HTML by default, while markdown requests are normalized for origin rendering and marked withVary: Acceptso Cloudflare's Markdown for Agents feature can return the converted markdown variant.The release workflow now enables Cloudflare's
content_converterzone setting after deployment and verifies thathttps://dxrating.net/searchresponds to markdown requests withContent-Type: text/markdown, loggingx-markdown-tokenswhen Cloudflare provides it.Testing
pnpm --filter @gekichumai/dxrating-web exec vitest run src/setup/__tests__/markdownNegotiation.test.tspnpm --filter @gekichumai/dxrating-web buildpnpm lintAccept: text/markdownreturned200 OKwithVary: Cookie, Accept-Language, Accept; plain requests returned200 OKHTML with the existing vary headers.