Skip to content

Commit

Permalink
suggestion(server): refactor request type
Browse files Browse the repository at this point in the history
  • Loading branch information
Вахрамеев Сергей Сергеевич authored and Вахрамеев Сергей Сергеевич committed Dec 19, 2024
1 parent c692a38 commit d12318d
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import {IncomingHttpHeaders, IncomingMessage} from 'http';
import { IncomingMessage } from 'http';

export type RequestHeaderType = IncomingMessage & {
headers: IncomingHttpHeaders & {
'app-version'?: string,
'user-agent': string,
},
params?: Record<string, string>;
query?: Record<string, string | string[]>;
body?: unknown;
url?: string;
};
// Универсальный request тип. При необходимости расширить.
//
// # Express 4 и 5 – подходит IncommingMessage.
// https://expressjs.com/en/5x/api.html#req
// > The req object is an enhanced version of Node’s own request object and supports all built-in fields and methods.
//
// # Hapi – подходит IncommingMessage.
// https://hapi.dev/api/?v=21.3.12#request.raw
// > An object containing the Node HTTP server objects.
//
// # Koa – подходит IncommingMessage.
// https://koajs.com/#request
// > A Koa Request object is an abstraction on top of node's vanilla request object,
// > providing additional functionality that is useful for every day HTTP server development.
//
// * Next.js 15 - подходит Request.
// https://nextjs.org/docs/app/api-reference/functions/next-request
// > NextRequest extends the Web Request API with additional convenience methods.
export type UniversalRequest = IncomingMessage | Request;

0 comments on commit d12318d

Please sign in to comment.