import * as keywork from "https://deno.land/x/keywork@v6.2.1/middleware/mod.ts";
Middleware are instances of the Keywork#Router.RequestRouter | RequestRouter
,
each with single responsibility
e.g. (users, blog posts, payments, authentication, etc.)
import { UsersRouter } from '@local/worker/routers/UsersRouter'
import { BlogRouter } from '@local/worker/routers/BlogRouter'
import { AuthenticationRouter } from '@local/worker/routers/AuthenticationRouter'
import { CloudflarePagesAssetRouter } from 'keywork/assets'
import { RequestRouter } from 'keywork/router'
// Create a router to receive all incoming requests...
const app = new RequestRouter({
// Here we combine our routers...
// highlight-start
middleware: [
AuthenticationRouter,
UsersRouter,
BlogRouter,
// And serve static assets...
new CloudflarePagesAssetRouter(),
],
// highlight-end
})
Middleware routers can perform any task that of single router such as...
- Executing any code
- Make changes to the request and the response of another router
- Terminate a request
- Intercept a request to check for authentication
- Call the next route handler in the stack
Built-in Middleware
Keywork includes a number of built-in middleware for common use cases:
- Keywork#Middleware.CompressionMiddleware | Automatic response compression
- Keywork#Middleware.SessionMiddleware | Basic session management
- Keywork#Middleware.CORSMiddleware | Cross-Origin Resource Sharing (CORS)
- Cloudflare
- Keywork#Middleware.CloudflarePagesAssetRouter | Serve static assets from Cloudflare Pages
- Keywork#Middleware.WorkerSitesAssetRouter | Serve static assets from a Worker Site
- Keywork#Middleware.ServiceBindingRouter | Proxy requests directly to another Cloudflare Worker
Classes
Handles incoming requests for static assets uploaded to Cloudflare Pages. | |
Middleware that given a | |
A router that proxies requests directly to a Cloudflare Worker environment binding, such as a service binding. | |
Middleware to manage and authenticate your users. | |
Handles incoming requests for static assets uploaded to Cloudflare KV. |
Variables
An asset environment binding available within Cloudflare Pages. | |
An asset environment binding available within Cloudflare Pages. | |
The default cookie serialization options. | |
The default session cookie key. |
Interfaces
Additional data associated with the | |
A simple session manager to aid in authenticating users. | |
An environment binding available within Worker Sites.
This is often used with the |
Type Aliases
The compression format used when encoding the response body. |