feat: add status method to Response interface and implement in Flummpress class
This commit is contained in:
parent
c6da7a4dd5
commit
c3ca8f5761
3
dist/index.js
vendored
3
dist/index.js
vendored
@ -117,6 +117,9 @@ export default class Flummpress {
|
|||||||
res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` });
|
res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` });
|
||||||
res.end(body);
|
res.end(body);
|
||||||
};
|
};
|
||||||
|
res.status = (code = 200) => {
|
||||||
|
return res.writeHead(code);
|
||||||
|
};
|
||||||
res.json = (body, code = 200) => {
|
res.json = (body, code = 200) => {
|
||||||
res.reply({ code, type: "application/json", body: JSON.stringify(body) });
|
res.reply({ code, type: "application/json", body: JSON.stringify(body) });
|
||||||
};
|
};
|
||||||
|
1
dist/router.d.ts
vendored
1
dist/router.d.ts
vendored
@ -17,6 +17,7 @@ export interface Response extends ServerResponse {
|
|||||||
type?: string;
|
type?: string;
|
||||||
body: string;
|
body: string;
|
||||||
}) => void;
|
}) => void;
|
||||||
|
status: (code: number) => Response;
|
||||||
json: (body: string, code?: number) => void;
|
json: (body: string, code?: number) => void;
|
||||||
html: (body: string, code?: number) => void;
|
html: (body: string, code?: number) => void;
|
||||||
redirect: (target: string, code?: number) => void;
|
redirect: (target: string, code?: number) => void;
|
||||||
|
@ -187,6 +187,10 @@ export default class Flummpress {
|
|||||||
res.end(body);
|
res.end(body);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
res.status = (code = 200) => {
|
||||||
|
return res.writeHead(code);
|
||||||
|
};
|
||||||
|
|
||||||
res.json = (body, code = 200) => {
|
res.json = (body, code = 200) => {
|
||||||
res.reply({ code, type: "application/json", body: JSON.stringify(body) });
|
res.reply({ code, type: "application/json", body: JSON.stringify(body) });
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@ export interface Request extends Omit<IncomingMessage, 'url'> {
|
|||||||
|
|
||||||
export interface Response extends ServerResponse {
|
export interface Response extends ServerResponse {
|
||||||
reply: (options: { code?: number; type?: string; body: string }) => void;
|
reply: (options: { code?: number; type?: string; body: string }) => void;
|
||||||
|
status: (code: number) => Response;
|
||||||
json: (body: string, code?: number) => void;
|
json: (body: string, code?: number) => void;
|
||||||
html: (body: string, code?: number) => void;
|
html: (body: string, code?: number) => void;
|
||||||
redirect: (target: string, code?: number) => void;
|
redirect: (target: string, code?: number) => void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user