Compare commits
15 Commits
21dc38b676
...
v3.2.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
d1c84cf6f6
|
|||
|
ba67b34a0d
|
|||
|
2d5bdfe40e
|
|||
|
7bb935fa53
|
|||
|
49d5806d89
|
|||
|
73a0d4a4f9
|
|||
|
24a85e9814
|
|||
|
dfdc50ba8a
|
|||
|
67bba2a339
|
|||
|
c21e91bcb6
|
|||
|
fe2f8ec227
|
|||
|
0e78ec4787
|
|||
|
fd7dce7256
|
|||
|
1d72a15ca6
|
|||
|
a740f1b103
|
@@ -1,4 +1,5 @@
|
||||
name: Publish
|
||||
run-name: Publish ${{ github.ref_name }}
|
||||
|
||||
on:
|
||||
release:
|
||||
@@ -13,19 +14,27 @@ jobs:
|
||||
with:
|
||||
node-version: latest
|
||||
registry-url: https://registry.npmjs.org/
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Publish to npmjs
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: npm publish --tag latest --access public
|
||||
run: npm publish --tag ${{ contains(github.ref_name, '-') && 'pre' || 'latest' }} --access public
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: latest
|
||||
registry-url: https://npm.pkg.github.com/
|
||||
|
||||
- name: Publish to GPR
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: npm publish --tag latest --access public
|
||||
run: npm publish --tag ${{ contains(github.ref_name, '-') && 'pre' || 'latest' }} --access public
|
||||
31
.github/workflows/release.yml
vendored
Normal file
31
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Release
|
||||
run-name: Release ${{ github.ref_name }}
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: latest
|
||||
registry-url: https://registry.npmjs.org/
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Create release
|
||||
run: gh release create ${{ github.ref_name }} --draft --generate-notes ${{ contains(github.ref_name, '-') && '--prerelease --latest=false' || '--latest' }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -15,7 +15,12 @@ jobs:
|
||||
with:
|
||||
node-version: latest
|
||||
registry-url: https://registry.npmjs.org/
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
@@ -18,8 +18,9 @@ When I was trying out Cloudflare Workers I almost immediately noticed how fast i
|
||||
- ZERO dependencies
|
||||
- Lightweight (1.0K gzipped)
|
||||
- Fully written in TypeScript
|
||||
- Integrated Debug-Mode & CORS helper
|
||||
- Built specifically around Middlewares
|
||||
- Debug-Mode, CORS and Bearer helpers
|
||||
- Allows accessing request body multiple times
|
||||
|
||||
|
||||
## Usage
|
||||
@@ -292,7 +293,7 @@ wrangler init <name>
|
||||
Use of TypeScript is strongly encouraged :)
|
||||
|
||||
```bash
|
||||
npm i -D @tsndr/cloudflare-worker-router
|
||||
npm i @tsndr/cloudflare-worker-router
|
||||
```
|
||||
|
||||
|
||||
|
||||
1210
package-lock.json
generated
1210
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tsndr/cloudflare-worker-router",
|
||||
"version": "3.2.4",
|
||||
"version": "3.2.10",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
@@ -32,9 +32,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/tsndr/cloudflare-worker-router#readme",
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20240222.0",
|
||||
"@edge-runtime/vm": "^3.2.0",
|
||||
"typescript": "^5.3.3",
|
||||
"vitest": "^1.3.1"
|
||||
"@cloudflare/workers-types": "^4.20241022.0",
|
||||
"@edge-runtime/vm": "^4.0.3",
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^2.1.3"
|
||||
}
|
||||
}
|
||||
17
src/index.ts
17
src/index.ts
@@ -406,21 +406,23 @@ export class Router<Env = any, CtxExt = {}, ReqExt = {}> {
|
||||
}
|
||||
|
||||
const route = this.getRoute(req)
|
||||
let response: Response | undefined
|
||||
|
||||
if (!route)
|
||||
return new Response(this.debugMode ? 'Route not found!' : null, { status: 404 })
|
||||
response = new Response(this.debugMode ? 'Route not found!' : null, { status: 404 })
|
||||
|
||||
const handlers = [...this.globalHandlers, ...route.handlers]
|
||||
const dbg = this.debugMode
|
||||
|
||||
let response: Response | undefined
|
||||
if (!response) {
|
||||
const handlers = [
|
||||
...this.globalHandlers,
|
||||
...(route?.handlers ?? [])
|
||||
]
|
||||
|
||||
for (const handler of handlers) {
|
||||
const context = {
|
||||
...(ctxExt ?? {}),
|
||||
env,
|
||||
req,
|
||||
dbg,
|
||||
dbg: this.debugMode,
|
||||
ctx
|
||||
} as RouterContext<Env, CtxExt, ReqExt>
|
||||
|
||||
@@ -431,9 +433,10 @@ export class Router<Env = any, CtxExt = {}, ReqExt = {}> {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!response)
|
||||
return new Response(this.debugMode ? 'Handler did not return a Response!' : null, { status: 404 })
|
||||
response = new Response(this.debugMode ? 'Handler did not return a Response!' : null, { status: 404 })
|
||||
|
||||
if (this.corsEnabled) {
|
||||
response = new Response(response.body, response)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": ".",
|
||||
"module": "commonjs",
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"lib": ["esnext"],
|
||||
"declaration": true,
|
||||
|
||||
Reference in New Issue
Block a user