diff --git a/dist/index.d.ts b/dist/index.d.ts index feb945f..37c10b9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -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?; diff --git a/dist/router.d.ts b/dist/router.d.ts index 4f5f609..daca185 100644 --- a/dist/router.d.ts +++ b/dist/router.d.ts @@ -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 { + url: { + pathname: string; + split: string[]; + searchParams: URLSearchParams; + qs: Record; + }; + cookies?: Record; + params?: Record; + post?: Record; +} +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; export default class Router { private routes; private tpl?; diff --git a/src/index.ts b/src/index.ts index a6e4647..c92065e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { diff --git a/src/router.ts b/src/router.ts index c54e199..8fc865f 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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 { + url: { + pathname: string; + split: string[]; + searchParams: URLSearchParams; + qs: Record; + }; + cookies?: Record; + params?: Record; + post?: Record; +} + +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; export default class Router { private routes: Array<{ path: string | RegExp; methods: { [method: string]: Handler[] } }> = []; diff --git a/src/types.d.ts b/src/types.d.ts deleted file mode 100644 index 38baae7..0000000 --- a/src/types.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IncomingMessage, ServerResponse } from "node:http"; - -export interface Request extends Omit { - url: { - pathname: string; - split: string[]; - searchParams: URLSearchParams; - qs: Record; - }; - cookies?: Record; - params?: Record; - post?: Record; -} - -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;