rjweb-server
Version:
Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS
69 lines (68 loc) • 2.23 kB
TypeScript
import { Method } from "../types/global";
import ValueCollection from "./ValueCollection";
import { EndFn, RateLimitConfig, RealAny } from "../types/internal";
import { UsableValidator } from "./Validator";
import { PathItemObject } from "openapi3-ts/oas31";
import HttpRequestContext from "./request/HttpRequestContext";
import WsOpenContext from "./request/WsOpenContext";
import WsMessageContext from "./request/WsMessageContext";
import WsCloseContext from "./request/WsCloseContext";
type Segment = {
raw: string;
paramsRegExp: RegExp;
params: string[];
};
type URLData = {
type: 'regexp';
value: RegExp;
prefix: string;
segments: Segment[];
} | {
type: 'normal';
value: string;
segments: Segment[];
};
type RequestType = 'http' | 'static' | 'ws';
type Data<Type extends RequestType> = Type extends 'http' ? {
onRawBody?(ctr: HttpRequestContext, end: EndFn, chunk: ArrayBuffer, isLast: boolean): RealAny;
onRequest?(ctr: HttpRequestContext): RealAny;
} : Type extends 'static' ? {
folder: string;
stripHtmlEnding: boolean;
} : {
onUpgrade?(ctr: HttpRequestContext, end: EndFn): RealAny;
onOpen?(ctr: WsOpenContext): RealAny;
onMessage?(ctr: WsMessageContext): RealAny;
onClose?(ctr: WsCloseContext): RealAny;
};
export default class Route<Type extends RequestType> {
type: Type;
private urlMethod;
urlData: URLData;
/**
* Create a new Route
* @since 9.0.0
*/ constructor(type: Type, urlMethod: Method, path: string | RegExp, data: Data<Type>);
/**
* The Data of this Route
* @since 9.0.0
*/ data: Data<Type>;
/**
* The Validators of this Route
* @since 9.0.0
*/ validators: UsableValidator[];
/**
* The Ratelimit of this Route
* @since 9.0.0
*/ ratelimit: Type extends 'static' ? null : RateLimitConfig | null;
/**
* The OpenAPI Schema of this Route
* @since 9.0.0
*/ openApi: PathItemObject;
/**
* Test the Path against the Request Path
* @warn NOT FOR STATIC ROUTES
* @since 9.0.0
*/ matches(method: Method, collection: ValueCollection<string, string>, requestPath: string, requestPathSplit: string[]): boolean;
}
export {};