edge

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BookmarkStore added in v0.0.10

func BookmarkStore(ctx router.Context) d1.BookmarkStore

BookmarkStore devuelve un d1.BookmarkStore respaldado por el almacen de cadenas por peticion de ctx. Es el enlace entre el router y el adaptador de D1: cada peticion lleva el suyo, asi que dos peticiones concurrentes en el mismo isolate nunca comparten version de la base.

func Dispatch

func Dispatch(r router.Router, ctx router.Context)

Dispatch drives ONE request through the full pipeline: identity, access gate, middleware, handler. It speaks only router.Context, so the pipeline that runs in production is the same one a test can drive — with no Cloudflare runtime and no js.Global() in sight.

That is not a convenience: the previous tests called the matched handler DIRECTLY, past the gate, which is why they stayed green while every guarded route answered 403 in production. A pipeline you cannot drive is a pipeline nobody tests.

func ExportCompile

func ExportCompile(r router.Router)

ExportCompile exports compile for testing.

func NewRouter

func NewRouter(cfg Config) router.Router

NewRouter builds the edge router. It takes a Config on purpose: the no-argument version could not authenticate anybody, which made every guarded route unreachable. An app with no auth passes edge.Config{} — explicitly.

func Serve

func Serve(r router.Router)

func Validate

func Validate(r router.Router)

Validate refuses to start on a contradiction. Each of these denies EVERY caller, forever, on a route that LOOKS protected — and the only way to discover that is a 403 in production, which is exactly how the file upload API shipped unusable.

It panics rather than returning an error: there is nobody to hand an error to at the top of a Worker, and goflare recovers and logs panics. Loud beats silent.

Types

type Config

type Config struct {
	// Authn establishes identity. It runs BEFORE the access gate, and that ordering is the
	// whole point: a gate that runs first can never be satisfied, so every guarded route
	// becomes a permanent 403. That is exactly the bug this replaced — it made the file
	// upload API unusable in production while the tests stayed green.
	//
	// It reads the request (cookie, header, token) and calls ctx.SetUserID. Anonymous ("")
	// is a legal outcome, not an error.
	Authn router.Middleware

	// Authorize answers whether that identity holds a permission. nil DENIES: the absence
	// of an answer is not permission.
	Authorize model.Authorizer
}

Config declares WHO the caller is and WHAT they may do. The library supplies the mechanism; the policy belongs to the app.

The zero value is legal — an app with no authentication — and its public routes work. What it cannot do is mount a guarded route without saying who authorizes it: Serve refuses to start on that contradiction, instead of answering 403 forever in silence.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL