diff --git a/dist/index.js b/dist/index.js index 9a44404..68ca1db 100644 --- a/dist/index.js +++ b/dist/index.js @@ -117,6 +117,9 @@ export default class Flummpress { res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` }); res.end(body); }; + res.status = (code = 200) => { + return res.writeHead(code); + }; res.json = (body, code = 200) => { res.reply({ code, type: "application/json", body: JSON.stringify(body) }); }; diff --git a/dist/router.d.ts b/dist/router.d.ts index daca185..e8f67e3 100644 --- a/dist/router.d.ts +++ b/dist/router.d.ts @@ -17,6 +17,7 @@ export interface Response extends ServerResponse { type?: string; body: string; }) => void; + status: (code: number) => Response; json: (body: string, code?: number) => void; html: (body: string, code?: number) => void; redirect: (target: string, code?: number) => void; diff --git a/src/index.ts b/src/index.ts index c92065e..2693825 100644 --- a/src/index.ts +++ b/src/index.ts @@ -187,6 +187,10 @@ export default class Flummpress { res.end(body); }; + res.status = (code = 200) => { + return res.writeHead(code); + }; + res.json = (body, code = 200) => { res.reply({ code, type: "application/json", body: JSON.stringify(body) }); }; diff --git a/src/router.ts b/src/router.ts index 8fc865f..062445b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -18,6 +18,7 @@ export interface Request extends Omit { export interface Response extends ServerResponse { reply: (options: { code?: number; type?: string; body: string }) => void; + status: (code: number) => Response; json: (body: string, code?: number) => void; html: (body: string, code?: number) => void; redirect: (target: string, code?: number) => void;