Files
cap/docs/guide/middleware/elysia.md
T
tiago 894c9e6ab9 feat: speculative challenges, jwt challenge tokens, standalone
optimizations, format
releases widget@0.1.38; standalone@2.2.0
2026-03-01 13:20:48 +00:00

911 B

Elysia checkpoint

Installation

bun add elysia @cap.js/middleware-elysia

[!NOTE] The template just needs to have a widget or hidden solver pointing at the /__cap_clearance URL. The sample template is here.

Usage

import { Elysia, file } from "elysia";
import { capMiddleware } from "@cap.js/middleware-elysia";

new Elysia()
  .use(
    capMiddleware({
      token_validity_hours: 32, // how long the token is valid for
      tokens_store_path: ".data/tokensList.json",
      token_size: 16, // token size in bytes
      verification_template_path: join(dirname(fileURLToPath(import.meta.url)), "./index.html"),
      scoping: "scoped", // 'global' | 'scoped'
    }),
  )
  .get("/", () => "Hello Elysia!")
  .listen(3000);

That's it! You can now use the middleware to protect your routes.