emdash-cms--emdash
b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
48 行
1.3 KiB
TypeScript
48 行
1.3 KiB
TypeScript
#!/usr/bin/env -S npx tsx
|
|
/**
|
|
* Generate a signed preview URL for local testing.
|
|
*
|
|
* Usage:
|
|
* npx tsx sign-url.ts [source] [preview]
|
|
*
|
|
* Defaults:
|
|
* source: http://localhost:4321
|
|
* preview: http://localhost:4322
|
|
* secret: reads PREVIEW_SECRET from .env, falls back to "dev-secret"
|
|
*/
|
|
|
|
import { readFileSync } from "node:fs";
|
|
|
|
const source = process.argv[2] || "http://localhost:4321";
|
|
const preview = process.argv[3] || "http://localhost:4322";
|
|
|
|
let secret = "dev-secret";
|
|
try {
|
|
const envFile = readFileSync(new URL(".env", import.meta.url), "utf-8");
|
|
const match = envFile.match(/^PREVIEW_SECRET\s*=\s*"?([^"\n]+)"?/m);
|
|
if (match) secret = match[1]!;
|
|
} catch {
|
|
// no .env, use default
|
|
}
|
|
|
|
const exp = Math.floor(Date.now() / 1000) + 3600;
|
|
const encoder = new TextEncoder();
|
|
|
|
const key = await crypto.subtle.importKey(
|
|
"raw",
|
|
encoder.encode(secret),
|
|
{ name: "HMAC", hash: "SHA-256" },
|
|
false,
|
|
["sign"],
|
|
);
|
|
|
|
const sigBuffer = await crypto.subtle.sign("HMAC", key, encoder.encode(`${source}:${exp}`));
|
|
const sig = Array.from(new Uint8Array(sigBuffer), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
|
|
const url = new URL(preview);
|
|
url.searchParams.set("source", source);
|
|
url.searchParams.set("exp", String(exp));
|
|
url.searchParams.set("sig", sig);
|
|
|
|
console.log(url.toString());
|