-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggestion(server): refactor request type
- Loading branch information
Вахрамеев Сергей Сергеевич
authored and
Вахрамеев Сергей Сергеевич
committed
Dec 19, 2024
1 parent
c692a38
commit d12318d
Showing
1 changed file
with
20 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |