Typescript 🖕
This commit is contained in:
parent
440d9788a2
commit
c6da7a4dd5
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,6 +1,5 @@
|
||||
import Router from "./router.js";
|
||||
import Router, { Request, Response, Handler } from "./router.js";
|
||||
import Tpl from "./template.js";
|
||||
import { Request, Response, Handler } from "./types.js";
|
||||
export { Router, Tpl, Request, Response, Handler };
|
||||
export default class Flummpress {
|
||||
private server?;
|
||||
|
24
dist/router.d.ts
vendored
24
dist/router.d.ts
vendored
@ -1,5 +1,27 @@
|
||||
import { IncomingMessage, ServerResponse } from "node:http";
|
||||
import Tpl from "./template.js";
|
||||
import { Handler } from "./types.js";
|
||||
export interface Request extends Omit<IncomingMessage, 'url'> {
|
||||
url: {
|
||||
pathname: string;
|
||||
split: string[];
|
||||
searchParams: URLSearchParams;
|
||||
qs: Record<string, string>;
|
||||
};
|
||||
cookies?: Record<string, string>;
|
||||
params?: Record<string, string>;
|
||||
post?: Record<string, string>;
|
||||
}
|
||||
export interface Response extends ServerResponse {
|
||||
reply: (options: {
|
||||
code?: number;
|
||||
type?: string;
|
||||
body: string;
|
||||
}) => void;
|
||||
json: (body: string, code?: number) => void;
|
||||
html: (body: string, code?: number) => void;
|
||||
redirect: (target: string, code?: number) => void;
|
||||
}
|
||||
export type Handler = (req: Request, res: Response, next?: () => void) => void | Promise<void>;
|
||||
export default class Router {
|
||||
private routes;
|
||||
private tpl?;
|
||||
|
@ -2,11 +2,9 @@ import http, { IncomingMessage, ServerResponse } from "node:http";
|
||||
import { URL } from "node:url";
|
||||
import querystring from "node:querystring";
|
||||
|
||||
import Router from "./router.js";
|
||||
import Router, { Request, Response, Handler } from "./router.js";
|
||||
import Tpl from "./template.js";
|
||||
|
||||
import { Request, Response, Handler } from "./types.js";
|
||||
|
||||
export { Router, Tpl, Request, Response, Handler };
|
||||
|
||||
export default class Flummpress {
|
||||
|
@ -1,8 +1,29 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { IncomingMessage, ServerResponse } from "node:http";
|
||||
|
||||
import Tpl from "./template.js";
|
||||
|
||||
import { Request, Response, Handler } from "./types.js";
|
||||
export interface Request extends Omit<IncomingMessage, 'url'> {
|
||||
url: {
|
||||
pathname: string;
|
||||
split: string[];
|
||||
searchParams: URLSearchParams;
|
||||
qs: Record<string, string>;
|
||||
};
|
||||
cookies?: Record<string, string>;
|
||||
params?: Record<string, string>;
|
||||
post?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface Response extends ServerResponse {
|
||||
reply: (options: { code?: number; type?: string; body: string }) => void;
|
||||
json: (body: string, code?: number) => void;
|
||||
html: (body: string, code?: number) => void;
|
||||
redirect: (target: string, code?: number) => void;
|
||||
}
|
||||
|
||||
export type Handler = (req: Request, res: Response, next?: () => void) => void | Promise<void>;
|
||||
|
||||
export default class Router {
|
||||
private routes: Array<{ path: string | RegExp; methods: { [method: string]: Handler[] } }> = [];
|
||||
|
22
src/types.d.ts
vendored
22
src/types.d.ts
vendored
@ -1,22 +0,0 @@
|
||||
import { IncomingMessage, ServerResponse } from "node:http";
|
||||
|
||||
export interface Request extends Omit<IncomingMessage, 'url'> {
|
||||
url: {
|
||||
pathname: string;
|
||||
split: string[];
|
||||
searchParams: URLSearchParams;
|
||||
qs: Record<string, string>;
|
||||
};
|
||||
cookies?: Record<string, string>;
|
||||
params?: Record<string, string>;
|
||||
post?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface Response extends ServerResponse {
|
||||
reply: (options: { code?: number; type?: string; body: string }) => void;
|
||||
json: (body: string, code?: number) => void;
|
||||
html: (body: string, code?: number) => void;
|
||||
redirect: (target: string, code?: number) => void;
|
||||
}
|
||||
|
||||
export type Handler = (req: Request, res: Response, next?: () => void) => void | Promise<void>;
|
Loading…
x
Reference in New Issue
Block a user