Private content: proxy mode
Use a proxy when the content needs a credential that must not reach the browser: a private Sanity dataset, a Strapi API token, a Contentful preview token on a staging site.
<script src="https://cdn.jsdelivr.net/npm/agentprose@0/dist/agentprose.min.js" defer data-adapter="sanity" data-project="abc123" data-proxy="https://cms-proxy.example.workers.dev"></script>With npm:
contentful({ space: 'xxxx', proxy: 'https://example.com/api/cms' }); // no token in the pageagentprose keeps the vendor’s path and query and swaps the origin for your proxy. The proxy:
- allow-lists read-only paths, so it can’t be used for anything else;
- adds the credential from its environment;
- forwards the request to the vendor and returns the JSON, with a short cache.
Ready-made proxies
Section titled “Ready-made proxies”The repository has two, in examples/proxy:
cf-proxy.js: a Cloudflare Worker. SetUPSTREAM,TOKENandALLOW_ORIGINas secrets or variables.node-proxy.mjs: Node 18+, no dependencies.
Checklist
Section titled “Checklist”- Allow only
GETand only the read endpoints your adapter uses. - Restrict CORS to your site’s origin (
ALLOW_ORIGIN). - Keep the token in the proxy’s environment, never in the page, the repository or the build output.
- Remember that whatever the proxy returns is now public to anyone who can call it, exactly like your published pages.