Typescript 🖕

This commit is contained in:
2025-03-19 13:57:32 +01:00
parent 440d9788a2
commit c6da7a4dd5
5 changed files with 47 additions and 29 deletions

3
dist/index.d.ts vendored
View File

@ -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
View File

@ -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?;