JSPM

@schemacompany/cloudflare

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q25258F
  • License MIT

Cloudflare Worker for edge-side schema injection

Package Exports

  • @schemacompany/cloudflare

Readme

@schemacompany/cloudflare

Cloudflare Worker for edge-side JSON-LD schema injection.

One-Click Deploy

Deploy this worker instantly to your Cloudflare account:

Deploy to Cloudflare

Installation

For manual setup or integration into existing projects:

npm install @schemacompany/cloudflare

Usage

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