feat: add status method to Response interface and implement in Flummpress class
This commit is contained in:
		
							
								
								
									
										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.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) });
 | 
			
		||||
        };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								dist/router.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								dist/router.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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) });
 | 
			
		||||
    };
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ export interface Request extends Omit<IncomingMessage, 'url'> {
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user