Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/connormckelvey/cloudflare-worker-router-typescript
Cloudflare Workers Router is a lightweight Express-like router with middleware support Cloudflare Workers and Durable Objects.
https://github.com/connormckelvey/cloudflare-worker-router-typescript
cloudflare durable-objects express router worker
Last synced: 15 days ago
JSON representation
Cloudflare Workers Router is a lightweight Express-like router with middleware support Cloudflare Workers and Durable Objects.
- Host: GitHub
- URL: https://github.com/connormckelvey/cloudflare-worker-router-typescript
- Owner: connormckelvey
- License: mit
- Created: 2022-03-07T11:05:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T17:21:07.000Z (over 2 years ago)
- Last Synced: 2024-09-21T06:57:19.956Z (2 months ago)
- Topics: cloudflare, durable-objects, express, router, worker
- Language: TypeScript
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudflare Worker Router
Cloudflare Workers Router is a lightweight Express-like router with middleware support Cloudflare Workers and Durable Objects. It began as a fork of [@tsndr/cloudflare-worker-router](https://github.com/tsndr/cloudflare-worker-router). The entire codebase has been converted to Typescript and a couple features have been added.
- Websocket support, for Cloudflare's `Response` object
- `router.use()`, for express-like global middleware
- Separate Cors middleware## Usage
`npm install cloudflare-worker-router`
```typescript
import { Router, RouterRequest, RouterResponse } from 'cloudflare-worker-router-typescript'const router = new Router()
interface Env {
FOO_OBJ: DurableObjectNamespace
}router.get('/echo/:foo/:bar', async (req: RouterRequest, res: RouterResponse) => {
console.log(req.env!.FOO_OBJ)
res.status = 200
res.body = { id: req.params }
})export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext) {
return router.handle(req, env, ctx)
}
}
```