@schemacompany/cloudflare
v0.1.1
Published
Cloudflare Worker for edge-side schema injection
Downloads
11
Readme
@schemacompany/cloudflare
Cloudflare Worker for edge-side JSON-LD schema injection.
One-Click Deploy
Deploy this worker instantly to your Cloudflare account:
Installation
For manual setup or integration into existing projects:
npm install @schemacompany/cloudflareUsage
Basic Setup
// src/index.ts
import schemaInjector from "@schemacompany/cloudflare";
export default schemaInjector;Configuration
Configure via wrangler.jsonc:
{
"name": "schema-injector",
"main": "src/index.ts",
"compatibility_date": "2024-01-01",
"vars": {
"SCHEMA_BASE_URL": "https://assets.theschemacompany.com",
"SCHEMA_MAPPINGS": "{\"/\":\"homepage-hash\",\"/about\":\"about-hash\"}"
}
}Configuration Methods
The worker determines which schema to inject using these methods (in order):
1. Response Header
Set X-Schema-Hash header from your origin:
X-Schema-Hash: your-64-char-hash...2. Path Mapping
Configure SCHEMA_MAPPINGS environment variable:
{
"/": "homepage-hash",
"/about": "about-hash",
"/products/*": "products-hash",
"/*": "fallback-hash"
}Supports exact paths, prefix matching (/*), and catch-all.
3. Meta Tag
Add a meta tag to your HTML:
<meta name="schema-hash" content="your-64-char-hash...">Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| SCHEMA_BASE_URL | API base URL | Production URL |
| SCHEMA_MAPPINGS | JSON path-to-hash mapping | {} |
Exports
import schemaInjector, {
type Env,
injectSchema,
extractMetaSchemaHash,
getBaseUrl,
getPathMappings,
getSchemaHashFromMappings,
} from "@schemacompany/cloudflare";License
MIT
