Compare commits
6 Commits
v3.2.9
...
a08adf3c03
| Author | SHA1 | Date | |
|---|---|---|---|
|
a08adf3c03
|
|||
|
2e594d09f5
|
|||
|
d1c84cf6f6
|
|||
|
ba67b34a0d
|
|||
|
2d5bdfe40e
|
|||
|
7bb935fa53
|
@@ -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
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
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
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
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
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@tsndr/cloudflare-worker-router",
|
||||
"version": "3.2.9",
|
||||
"version": "3.2.10",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@tsndr/cloudflare-worker-router",
|
||||
"version": "3.2.9",
|
||||
"version": "3.2.10",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20241022.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tsndr/cloudflare-worker-router",
|
||||
"version": "3.2.9",
|
||||
"version": "3.2.10",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
|
||||
@@ -52,6 +52,7 @@ export type RouterRequest<ReqExt> = ReqExt & {
|
||||
formData(): Promise<FormData>
|
||||
blob(): Promise<Blob>
|
||||
bearer(): string | undefined
|
||||
basic(): [string, string]
|
||||
cf?: IncomingRequestCfProperties
|
||||
}
|
||||
|
||||
@@ -395,7 +396,8 @@ export class Router<Env = any, CtxExt = {}, ReqExt = {}> {
|
||||
json: async <T>(): Promise<T> => buffer.json ? buffer.json : buffer.json = await request.clone().json<T>(),
|
||||
formData: async (): Promise<FormData> => buffer.formData ? buffer.formData : buffer.formData = await request.clone().formData(),
|
||||
blob: async (): Promise<Blob> => buffer.blob ? buffer.blob : buffer.blob = await request.clone().blob(),
|
||||
bearer: () => request.headers.get('Authorization')?.replace(/^(B|b)earer /, '').trim()
|
||||
bearer: () => request.headers.get('Authorization')?.replace(/^[Bb]earer\s/, '').trim(),
|
||||
basic: () => (atob(request.headers.get('Authorization')?.replace(/^[Bb]asic\s/, '').trim() ?? '') || undefined)?.split(':')
|
||||
} as RouterRequest<ReqExt>
|
||||
|
||||
if (this.corsEnabled && req.method === 'OPTIONS') {
|
||||
|
||||
@@ -261,6 +261,21 @@ describe('Router', () => {
|
||||
|
||||
expect(await response.text()).toBe(testToken)
|
||||
})
|
||||
|
||||
test('basic', async () => {
|
||||
const router = new Router()
|
||||
const testCredentials = ['user', 'password']
|
||||
const testBasicAuth = btoa(testCredentials.join(':'))
|
||||
const testRequest = new Request('https://example.com/', { headers: { 'Authorization': `Basic ${testBasicAuth}` }})
|
||||
|
||||
router.get('/', ({ req }) => Response.json(req.basic()))
|
||||
|
||||
const response = await router.handle(testRequest, {})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(await response.json()).toMatchObject(testCredentials)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Middleware', () => {
|
||||
|
||||
Reference in New Issue
Block a user