Files
moreminimore-redesign/packages/x402/src/middleware.ts
Matt Kane c7d2401b8b fix: resolve all lint warnings and fix failing playground toolbar test
- Fix playground-toolbar test: URL changed to github.com but test still expected docs.emdashcms.com
- create-emdash: extract selectTemplate() to eliminate unsafe/unnecessary type assertions
- create-emdash: use type-safe Object.keys filter instead of bare cast
- cloudflare/cache: use Reflect.get with typeof guard instead of double type assertion
- x402/enforcer: replace unsafe request cast with Reflect.get type guards for CF bot management
- x402/middleware: suppress unavoidable virtual module any-cast with eslint comment
2026-04-01 15:35:06 +01:00

26 lines
878 B
TypeScript

/**
* x402 Astro Middleware
*
* Injected by the x402 integration. Creates the enforcer and
* places it on Astro.locals.x402 for use in page frontmatter.
*
* The config is passed via the virtual module resolved by the integration.
*/
import { defineMiddleware } from "astro:middleware";
// The integration injects config via a virtual module.
// @ts-ignore -- virtual module, resolved at build time
import x402Config from "virtual:x402/config";
import { createEnforcer } from "./enforcer.js";
import type { X402Config } from "./types.js";
// eslint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- virtual module import has no type info
const config: X402Config = x402Config as X402Config;
const enforcer = createEnforcer(config);
export const onRequest = defineMiddleware(async (context, next) => {
context.locals.x402 = enforcer;
return next();
});