Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
6f84645f89
|
|||
|
53f8365993
|
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-router",
|
"name": "@tsndr/cloudflare-worker-router",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@tsndr/cloudflare-worker-router",
|
"name": "@tsndr/cloudflare-worker-router",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^3.13.0",
|
"@cloudflare/workers-types": "^3.13.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-router",
|
"name": "@tsndr/cloudflare-worker-router",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
|
|||||||
24
src/index.ts
24
src/index.ts
@@ -6,7 +6,7 @@
|
|||||||
* @property {string} url URL String
|
* @property {string} url URL String
|
||||||
* @property {RouterHandler[]} handlers Array of handler functions
|
* @property {RouterHandler[]} handlers Array of handler functions
|
||||||
*/
|
*/
|
||||||
interface Route {
|
export interface Route {
|
||||||
method: string
|
method: string
|
||||||
url: string
|
url: string
|
||||||
handlers: RouterHandler[]
|
handlers: RouterHandler[]
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
* @property {RouterResponse} res Response Object
|
* @property {RouterResponse} res Response Object
|
||||||
* @property {RouterNext} next Next Handler
|
* @property {RouterNext} next Next Handler
|
||||||
*/
|
*/
|
||||||
interface RouterContext {
|
export interface RouterContext {
|
||||||
env: any
|
env: any
|
||||||
req: RouterRequest
|
req: RouterRequest
|
||||||
res: RouterResponse
|
res: RouterResponse
|
||||||
@@ -40,7 +40,7 @@ interface RouterContext {
|
|||||||
* @property {any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent.
|
* @property {any} body Only available if method is `POST`, `PUT`, `PATCH` or `DELETE`. Contains either the received body string or a parsed object if valid JSON was sent.
|
||||||
* @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object)
|
* @property {IncomingRequestCfProperties} [cf] object containing custom Cloudflare properties. (https://developers.cloudflare.com/workers/examples/accessing-the-cloudflare-object)
|
||||||
*/
|
*/
|
||||||
interface RouterRequest {
|
export interface RouterRequest {
|
||||||
url: string
|
url: string
|
||||||
method: string
|
method: string
|
||||||
params: RouterRequestParams
|
params: RouterRequestParams
|
||||||
@@ -48,6 +48,7 @@ interface RouterRequest {
|
|||||||
headers: Headers
|
headers: Headers
|
||||||
body: any
|
body: any
|
||||||
cf?: IncomingRequestCfProperties
|
cf?: IncomingRequestCfProperties
|
||||||
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +56,7 @@ interface RouterRequest {
|
|||||||
*
|
*
|
||||||
* @typedef RouterRequestParams
|
* @typedef RouterRequestParams
|
||||||
*/
|
*/
|
||||||
interface RouterRequestParams {
|
export interface RouterRequestParams {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ interface RouterRequestParams {
|
|||||||
*
|
*
|
||||||
* @typedef RouterRequestQuery
|
* @typedef RouterRequestQuery
|
||||||
*/
|
*/
|
||||||
interface RouterRequestQuery {
|
export interface RouterRequestQuery {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ interface RouterRequestQuery {
|
|||||||
* @property {any} [body] Either an `object` (will be converted to JSON) or a string
|
* @property {any} [body] Either an `object` (will be converted to JSON) or a string
|
||||||
* @property {Response} [raw] A response object that is to be returned, this will void all other res properties and return this as is.
|
* @property {Response} [raw] A response object that is to be returned, this will void all other res properties and return this as is.
|
||||||
*/
|
*/
|
||||||
interface RouterResponse {
|
export interface RouterResponse {
|
||||||
headers: Headers
|
headers: Headers
|
||||||
status?: number
|
status?: number
|
||||||
body?: any
|
body?: any
|
||||||
@@ -91,7 +92,7 @@ interface RouterResponse {
|
|||||||
* @callback RouterNext
|
* @callback RouterNext
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
interface RouterNext {
|
export interface RouterNext {
|
||||||
(): Promise<void>
|
(): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ interface RouterNext {
|
|||||||
* @param {RouterContext} ctx
|
* @param {RouterContext} ctx
|
||||||
* @returns {Promise<void> | void}
|
* @returns {Promise<void> | void}
|
||||||
*/
|
*/
|
||||||
interface RouterHandler {
|
export interface RouterHandler {
|
||||||
(ctx: RouterContext): Promise<void> | void
|
(ctx: RouterContext): Promise<void> | void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ interface RouterHandler {
|
|||||||
* @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`)
|
* @property {number} [maxAge=86400] Access-Control-Max-Age (default: `86400`)
|
||||||
* @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`)
|
* @property {number} [optionsSuccessStatus=204] Return status code for OPTIONS request (default: `204`)
|
||||||
*/
|
*/
|
||||||
interface RouterCorsConfig {
|
export interface RouterCorsConfig {
|
||||||
allowOrigin: string
|
allowOrigin: string
|
||||||
allowMethods: string
|
allowMethods: string
|
||||||
allowHeaders: string
|
allowHeaders: string
|
||||||
@@ -124,14 +125,13 @@ interface RouterCorsConfig {
|
|||||||
optionsSuccessStatus: number
|
optionsSuccessStatus: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router
|
* Router
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
class Router {
|
export default class Router {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router Array
|
* Router Array
|
||||||
@@ -448,5 +448,3 @@ class Router {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Router
|
|
||||||
|
|||||||
Reference in New Issue
Block a user