rjweb-server
Advanced tools
Comparing version 1.2.4 to 1.2.5
export { default as ctr } from "./src/interfaces/ctr" | ||
export { ctrError } from "./src/interfaces/ctr" | ||
export { default as page } from "./src/interfaces/page" | ||
export { default as types } from "./src/interfaces/types" | ||
export { default as ratelimitRule } from "./src/interfaces/ratelimitRule" |
@@ -1,2 +0,3 @@ | ||
import ctr, { ctrError } from "./interfaces/ctr"; | ||
/// <reference types="node" /> | ||
import ctr from "./interfaces/ctr"; | ||
import routeList from "./classes/routeList"; | ||
@@ -6,6 +7,7 @@ import rateLimitRule from "./interfaces/ratelimitRule"; | ||
import page from "./interfaces/page"; | ||
import * as http from "http"; | ||
interface startOptions { | ||
pages?: { | ||
/** When a Route is not found */ notFound?: (ctr: ctr) => Promise<any>; | ||
/** When an Error occurs in a Route */ reqError?: (ctr: ctrError) => Promise<any>; | ||
/** When an Error occurs in a Route */ reqError?: (ctr: ctr<any, true>) => Promise<any>; | ||
}; | ||
@@ -20,3 +22,3 @@ events?: { | ||
/** | ||
* If true Ratelimits are enabled | ||
* Whether Ratelimits are enabled | ||
* @default false | ||
@@ -35,3 +37,3 @@ */ enabled: boolean; | ||
get: (key: string) => Promise<any>; | ||
} | Map<any, any>; | ||
} | Map<string, number>; | ||
}; | ||
@@ -43,7 +45,7 @@ /** | ||
/** | ||
* If true X-Forwarded-For will be shown as hostIp | ||
* Whether X-Forwarded-For will be shown as hostIp | ||
* @default false | ||
*/ proxy?: boolean; | ||
/** | ||
* If true all cors headers are set | ||
* Whether all cors headers are set | ||
* @default false | ||
@@ -63,5 +65,11 @@ */ cors?: boolean; | ||
types: typeof typesEnum; | ||
start(options: startOptions): Promise<unknown>; | ||
start(options: startOptions): Promise<{ | ||
success: boolean; | ||
port?: number; | ||
error?: Error; | ||
message: string; | ||
rawServer?: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>; | ||
}>; | ||
}; | ||
export = _default; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -147,3 +147,3 @@ "use strict"; | ||
const cookies = new Map(); | ||
if (!!req.headers.cookie) { | ||
if (req.headers.cookie) { | ||
req.headers.cookie.split(';').forEach((cookie) => { | ||
@@ -150,0 +150,0 @@ let [name, ...rest] = cookie.split('='); |
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
} | ||
export default interface ctr<Custom = any> { | ||
export default interface ctr<Custom = {}, HasError = false> { | ||
/** A Map of all Headers */ readonly header: Map<Lowercase<string>, string>; | ||
@@ -27,2 +27,3 @@ /** A Map of all Cookies */ readonly cookie: Map<string, string>; | ||
/** The Raw HTTP Server Res Variable */ rawRes: ServerResponse; | ||
/** The Error from the Request */ error?: HasError extends true ? Error : undefined; | ||
/** Set an HTTP Header to add */ setHeader: (name: string, value: string) => ctr; | ||
@@ -33,8 +34,5 @@ /** Set a Custom Variable */ setCustom: <Type extends keyof Custom>(name: Type, value: Custom[Type]) => ctr; | ||
/** Print the Content of a File to the Client */ printFile: (path: string) => ctr; | ||
/** Custom Variables */ '@': Custom; | ||
/** Custom Variables that are Global */ '@': Custom; | ||
} | ||
export interface ctrError extends ctr { | ||
/** The Error */ error: Error; | ||
} | ||
export {}; | ||
//# sourceMappingURL=ctr.d.ts.map |
@@ -8,6 +8,6 @@ /// <reference types="node" /> | ||
/** The HTTP Request Type */ type: types; | ||
/** If true then some Content Types will be added automatically */ addTypes: boolean; | ||
/** The Async Code to run on a Request */ code: (ctr: ctr) => void; | ||
/** Whether then some Content Types will be added automatically */ addTypes: boolean; | ||
/** The Async Code to run on a Request */ code: (ctr: ctr) => Promise<any>; | ||
/** The File Content (If Preloading) */ content?: Buffer; | ||
} | ||
//# sourceMappingURL=page.d.ts.map |
{ | ||
"name": "rjweb-server", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Easy and Lightweight Way to create a Web Server in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
import ctr, { ctrError } from "./interfaces/ctr" | ||
import ctr from "./interfaces/ctr" | ||
import routeList from "./classes/routeList" | ||
@@ -16,3 +16,3 @@ import rateLimitRule from "./interfaces/ratelimitRule" | ||
/** When a Route is not found */ notFound?: (ctr: ctr) => Promise<any> | ||
/** When an Error occurs in a Route */ reqError?: (ctr: ctrError) => Promise<any> | ||
/** When an Error occurs in a Route */ reqError?: (ctr: ctr<any, true>) => Promise<any> | ||
}, events?: { | ||
@@ -24,3 +24,3 @@ /** On Every Request */ request?: (ctr: ctr) => Promise<any> | ||
/** | ||
* If true Ratelimits are enabled | ||
* Whether Ratelimits are enabled | ||
* @default false | ||
@@ -39,3 +39,3 @@ */ enabled: boolean | ||
get: (key: string) => Promise<any> | ||
} | Map<any, any> | ||
} | Map<string, number> | ||
} | ||
@@ -48,7 +48,7 @@ | ||
/** | ||
* If true X-Forwarded-For will be shown as hostIp | ||
* Whether X-Forwarded-For will be shown as hostIp | ||
* @default false | ||
*/ proxy?: boolean | ||
/** | ||
* If true all cors headers are set | ||
* Whether all cors headers are set | ||
* @default false | ||
@@ -181,3 +181,3 @@ */ cors?: boolean | ||
}; const cookies = new Map() | ||
if (!!req.headers.cookie) { | ||
if (req.headers.cookie) { | ||
req.headers.cookie.split(';').forEach((cookie: string) => { | ||
@@ -251,4 +251,4 @@ let [name, ...rest] = cookie.split('=') | ||
if ('reqError' in pages) { | ||
(ctr as ctrError).error = e | ||
Promise.resolve(pages.reqError(ctr as ctrError)).catch((e) => { | ||
ctr.error = e | ||
Promise.resolve(pages.reqError(ctr as unknown as ctr<any, true>)).catch((e) => { | ||
console.log(e) | ||
@@ -283,4 +283,4 @@ res.statusCode = 500 | ||
if ('reqError' in pages) { | ||
(ctr as ctrError).error = e | ||
Promise.resolve(pages.reqError(ctr as ctrError)).catch((e) => { | ||
ctr.error = e | ||
Promise.resolve(pages.reqError(ctr as unknown as ctr<any, true>)).catch((e) => { | ||
console.log(e) | ||
@@ -325,4 +325,4 @@ res.statusCode = 500 | ||
if ('reqError' in pages) { | ||
(ctr as any).error = e | ||
Promise.resolve(pages.reqError(ctr as ctrError)).catch((e) => { | ||
ctr.error = e | ||
Promise.resolve(pages.reqError(ctr as unknown as ctr<any, true>)).catch((e) => { | ||
console.log(e) | ||
@@ -372,4 +372,4 @@ res.statusCode = 500 | ||
if ('reqError' in pages) { | ||
(ctr as ctrError).error = e | ||
pages.reqError(ctr as ctrError).catch((e) => { | ||
ctr.error = e | ||
pages.reqError(ctr as unknown as ctr<any, true>).catch((e) => { | ||
console.log(e) | ||
@@ -418,4 +418,4 @@ res.statusCode = 500 | ||
server.once('error', (error) => reject({ success: false, error, message: 'WEBSERVER ERRORED' })) | ||
}) | ||
}) as Promise<{ success: boolean, port?: number, error?: Error, message: string, rawServer?: typeof server }> | ||
} | ||
} |
@@ -12,3 +12,3 @@ import { Server, IncomingMessage, ServerResponse } from "http" | ||
export default interface ctr<Custom = any> { | ||
export default interface ctr<Custom = {}, HasError = false> { | ||
/** A Map of all Headers */ readonly header: Map<Lowercase<string>, string> | ||
@@ -28,2 +28,4 @@ /** A Map of all Cookies */ readonly cookie: Map<string, string> | ||
/** The Error from the Request */ error?: HasError extends true ? Error : undefined | ||
/** Set an HTTP Header to add */ setHeader: (name: string, value: string) => ctr | ||
@@ -35,7 +37,3 @@ /** Set a Custom Variable */ setCustom: <Type extends keyof Custom>(name: Type, value: Custom[Type]) => ctr | ||
/** Custom Variables */ '@': Custom | ||
} | ||
export interface ctrError extends ctr { | ||
/** The Error */ error: Error | ||
/** Custom Variables that are Global */ '@': Custom | ||
} |
@@ -8,5 +8,5 @@ import { types } from "./types" | ||
/** The HTTP Request Type */ type: types | ||
/** If true then some Content Types will be added automatically */ addTypes: boolean | ||
/** The Async Code to run on a Request */ code: (ctr: ctr) => void | ||
/** Whether then some Content Types will be added automatically */ addTypes: boolean | ||
/** The Async Code to run on a Request */ code: (ctr: ctr) => Promise<any> | ||
/** The File Content (If Preloading) */ content?: Buffer | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87605
1361