add editorconfig
This commit is contained in:
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = false
|
||||||
|
|
||||||
|
[src/**.ts]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = tab
|
||||||
138
src/index.ts
138
src/index.ts
@@ -1,26 +1,26 @@
|
|||||||
/**
|
/**
|
||||||
* Route Object
|
* Route Object
|
||||||
*
|
*
|
||||||
* @typedef Route
|
* @typedef Route
|
||||||
* @property {string} method HTTP request method
|
* @property {string} method HTTP request method
|
||||||
* @property {string} url URL String
|
* @property {string} url URL String
|
||||||
* @property {RouterHandler[]} handlers Array of handler functions
|
* @property {RouterHandler[]} handlers Array of handler functions
|
||||||
*/
|
*/
|
||||||
export interface Route<TEnv> {
|
export interface Route<TEnv> {
|
||||||
method: string
|
method: string
|
||||||
url: string
|
url: string
|
||||||
handlers: RouterHandler<TEnv>[]
|
handlers: RouterHandler<TEnv>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router Context
|
* Router Context
|
||||||
*
|
*
|
||||||
* @typedef RouterContext
|
* @typedef RouterContext
|
||||||
* @property {RouterEnv} env Environment
|
* @property {RouterEnv} env Environment
|
||||||
* @property {RouterRequest} req Request Object
|
* @property {RouterRequest} req Request Object
|
||||||
* @property {RouterResponse} res Response Object
|
* @property {RouterResponse} res Response Object
|
||||||
* @property {RouterNext} next Next Handler
|
* @property {RouterNext} next Next Handler
|
||||||
*/
|
*/
|
||||||
export interface RouterContext<TEnv> {
|
export interface RouterContext<TEnv> {
|
||||||
env: TEnv
|
env: TEnv
|
||||||
req: RouterRequest
|
req: RouterRequest
|
||||||
@@ -29,17 +29,17 @@ export interface RouterContext<TEnv> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Object
|
* Request Object
|
||||||
*
|
*
|
||||||
* @typedef RouterRequest
|
* @typedef RouterRequest
|
||||||
* @property {string} url URL
|
* @property {string} url URL
|
||||||
* @property {string} method HTTP request method
|
* @property {string} method HTTP request method
|
||||||
* @property {RouterRequestParams} params Object containing all parameters defined in the url string
|
* @property {RouterRequestParams} params Object containing all parameters defined in the url string
|
||||||
* @property {RouterRequestQuery} query Object containing all query parameters
|
* @property {RouterRequestQuery} query Object containing all query parameters
|
||||||
* @property {Headers} headers Request headers object
|
* @property {Headers} headers Request headers object
|
||||||
* @property {string | 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 {string | 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)
|
||||||
*/
|
*/
|
||||||
export interface RouterRequest {
|
export interface RouterRequest {
|
||||||
url: string
|
url: string
|
||||||
method: string
|
method: string
|
||||||
@@ -52,32 +52,32 @@ export interface RouterRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Parameters
|
* Request Parameters
|
||||||
*
|
*
|
||||||
* @typedef RouterRequestParams
|
* @typedef RouterRequestParams
|
||||||
*/
|
*/
|
||||||
export interface RouterRequestParams {
|
export interface RouterRequestParams {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Query
|
* Request Query
|
||||||
*
|
*
|
||||||
* @typedef RouterRequestQuery
|
* @typedef RouterRequestQuery
|
||||||
*/
|
*/
|
||||||
export interface RouterRequestQuery {
|
export interface RouterRequestQuery {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response Object
|
* Response Object
|
||||||
*
|
*
|
||||||
* @typedef RouterResponse
|
* @typedef RouterResponse
|
||||||
* @property {Headers} headers Response headers object
|
* @property {Headers} headers Response headers object
|
||||||
* @property {number} [status=204] Return status code (default: `204`)
|
* @property {number} [status=204] Return status code (default: `204`)
|
||||||
* @property {string | any} [body] Either an `object` (will be converted to JSON) or a string
|
* @property {string | 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.
|
||||||
*/
|
*/
|
||||||
export interface RouterResponse {
|
export interface RouterResponse {
|
||||||
headers: Headers
|
headers: Headers
|
||||||
status?: number
|
status?: number
|
||||||
@@ -87,36 +87,36 @@ export interface RouterResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Next Function
|
* Next Function
|
||||||
*
|
*
|
||||||
* @callback RouterNext
|
* @callback RouterNext
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
export interface RouterNext {
|
export interface RouterNext {
|
||||||
(): Promise<void>
|
(): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler Function
|
* Handler Function
|
||||||
*
|
*
|
||||||
* @callback RouterHandler
|
* @callback RouterHandler
|
||||||
* @param {RouterContext} ctx
|
* @param {RouterContext} ctx
|
||||||
* @returns {Promise<void> | void}
|
* @returns {Promise<void> | void}
|
||||||
*/
|
*/
|
||||||
export interface RouterHandler<TEnv = any> {
|
export interface RouterHandler<TEnv = any> {
|
||||||
(ctx: RouterContext<TEnv>): Promise<void> | void
|
(ctx: RouterContext<TEnv>): Promise<void> | void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CORS Config
|
* CORS Config
|
||||||
*
|
*
|
||||||
* @typedef RouterCorsConfig
|
* @typedef RouterCorsConfig
|
||||||
* @property {string} [allowOrigin="*"] Access-Control-Allow-Origin (default: `*`)
|
* @property {string} [allowOrigin="*"] Access-Control-Allow-Origin (default: `*`)
|
||||||
* @property {string} [allowMethods="*"] Access-Control-Allow-Methods (default: `*`)
|
* @property {string} [allowMethods="*"] Access-Control-Allow-Methods (default: `*`)
|
||||||
* @property {string} [allowHeaders="*"] Access-Control-Allow-Headers (default: `*`)
|
* @property {string} [allowHeaders="*"] Access-Control-Allow-Headers (default: `*`)
|
||||||
* @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`)
|
||||||
*/
|
*/
|
||||||
export interface RouterCorsConfig {
|
export interface RouterCorsConfig {
|
||||||
allowOrigin?: string
|
allowOrigin?: string
|
||||||
allowMethods?: string
|
allowMethods?: string
|
||||||
@@ -126,11 +126,11 @@ export interface RouterCorsConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router
|
* Router
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
export class Router<TEnv = any> {
|
export class Router<TEnv = any> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +167,7 @@ export class Router<TEnv = any> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CORS enabled
|
* CORS enabled
|
||||||
*-
|
*
|
||||||
* @protected
|
* @protected
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user