itty-router 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -1
- package/README.md +23 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
Until this library makes it to a production release of v1.x, **minor versions may contain breaking changes to the API**. After v1.x, semantic versioning will be honored, and breaking changes will only occur under the umbrella of a major version bump.
|
|
3
3
|
|
|
4
|
-
[@SupremeTechnopriest)(https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D
|
|
4
|
+
[@SupremeTechnopriest)(https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D\
|
|
5
|
+
|
|
6
|
+
- **v2.5.1** - added context to Cloudflare ES module syntax example (credit [@jcapogna](https://github.com/jcapogna))
|
|
5
7
|
- **v2.5.0** - improved TypeScript docs/types (thanks [@SupremeTechnopriest](https://github.com/SupremeTechnopriest)!)
|
|
6
8
|
- **v2.4.9** - fixed the cursed "optional" file format capturing bug - RIP all the bytes lost
|
|
7
9
|
- **v2.4.6** - fixed README issues
|
package/README.md
CHANGED
|
@@ -283,16 +283,33 @@ router.get('/todos/:id.:format?', request => {
|
|
|
283
283
|
```
|
|
284
284
|
|
|
285
285
|
### Cloudflare ES6 Module Syntax (required for Durable Objects) <a id="cf-es6-module-syntax"></a>
|
|
286
|
+
See https://developers.cloudflare.com/workers/runtime-apis/fetch-event#syntax-module-worker
|
|
286
287
|
```js
|
|
288
|
+
import { Router } from 'itty-router'
|
|
289
|
+
|
|
287
290
|
const router = Router()
|
|
288
291
|
|
|
289
|
-
router.get('/', (request, env) => {
|
|
292
|
+
router.get('/', (request, env, context) => {
|
|
290
293
|
// now have access to the env (where CF bindings like durables, KV, etc now are)
|
|
291
294
|
})
|
|
292
295
|
|
|
293
296
|
export default {
|
|
294
297
|
fetch: router.handle // yep, it's this easy.
|
|
295
298
|
}
|
|
299
|
+
|
|
300
|
+
// alternative advanced/manual approach for downstream control
|
|
301
|
+
export default {
|
|
302
|
+
fetch: (...args) => router
|
|
303
|
+
.handle(...args)
|
|
304
|
+
.then(response =>
|
|
305
|
+
// can modify response here before final return, e.g. CORS headers
|
|
306
|
+
|
|
307
|
+
return response
|
|
308
|
+
})
|
|
309
|
+
.catch(err => {
|
|
310
|
+
// and do something with the errors here, like logging, error status, etc
|
|
311
|
+
})
|
|
312
|
+
}
|
|
296
313
|
```
|
|
297
314
|
|
|
298
315
|
### Extending itty router
|
|
@@ -558,4 +575,8 @@ These folks are the real heroes, making open source the powerhouse that it is!
|
|
|
558
575
|
- [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
|
|
559
576
|
- [@roojay520](https://github.com/roojay520) - TS interface fixes
|
|
560
577
|
#### Documentation
|
|
561
|
-
- [@arunsathiya](https://github.com/arunsathiya),
|
|
578
|
+
- [@arunsathiya](https://github.com/arunsathiya),
|
|
579
|
+
[@poacher2k](https://github.com/poacher2k),
|
|
580
|
+
[@ddarkr](https://github.com/ddarkr),
|
|
581
|
+
[@kclauson](https://github.com/kclauson),
|
|
582
|
+
[@jcapogna](https://github.com/jcapogna)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-router",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Tiny, zero-dependency router with route param and query parsing - built for Cloudflare Workers, but works everywhere!",
|
|
5
5
|
"main": "./dist/itty-router.min.js",
|
|
6
6
|
"types": "./dist/itty-router.d.ts",
|