forked from tinyhttp/milliparsec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: don't populate
req.body
, return the parsed body instead
- Loading branch information
1 parent
ddf091b
commit 65e64c8
Showing
16 changed files
with
122 additions
and
170 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
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,13 @@ | ||
import { getRead } from '@/get-read' | ||
import type { HasBody, MaybeParsed, NextFunction, Request, Response } from '@/types' | ||
import type { MaybeParsed, Request, Response } from '@/types' | ||
import { alreadyParsed } from '@/utils/already-parsed-symbol' | ||
import { hasNoBody } from '@/utils/has-no-body' | ||
|
||
export const custom = <T = unknown>(fn: (body: string) => T) => { | ||
export const makeCustom = <T = unknown>(fn: (body: string) => T) => { | ||
const read = getRead(fn) | ||
return async (req: Request & HasBody<T> & MaybeParsed, res: Response, next: NextFunction) => { | ||
if (req[alreadyParsed] === true) return next() | ||
req.body = await read(req, res) | ||
next() | ||
return async (req: Request & MaybeParsed, res: Response): Promise<T | undefined> => { | ||
if (req[alreadyParsed] === true) return undefined | ||
if (hasNoBody(req.method)) return undefined | ||
return await read(req, res) | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.