-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3292 from SeedCompany/fastify
- Loading branch information
Showing
13 changed files
with
910 additions
and
536 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
FASTIFY_ROUTE_CONFIG_METADATA, | ||
FASTIFY_ROUTE_CONSTRAINTS_METADATA, | ||
} from '@nestjs/platform-fastify/constants.js'; | ||
import { Many } from '@seedcompany/common'; | ||
import { createMetadataDecorator } from '@seedcompany/nest'; | ||
import { FastifyContextConfig } from 'fastify'; | ||
import type { RouteConstraint } from 'fastify/types/route'; | ||
|
||
export const RouteConstraints = createMetadataDecorator({ | ||
key: FASTIFY_ROUTE_CONSTRAINTS_METADATA, | ||
types: ['class', 'method'], | ||
setter: (config: RouteConstraint) => config, | ||
}); | ||
|
||
export const RouteConfig = createMetadataDecorator({ | ||
key: FASTIFY_ROUTE_CONFIG_METADATA, | ||
types: ['class', 'method'], | ||
setter: (config: FastifyContextConfig) => config, | ||
}); | ||
|
||
/** | ||
* @example | ||
* ```ts | ||
* @RawBody() | ||
* route( | ||
* @Request('rawBody') raw: string, | ||
* @Body() contents: JSON | ||
* ) {} | ||
* ``` | ||
* @example | ||
* ```ts | ||
* @RawBody({ passthrough: true }) | ||
* route( | ||
* @Body() contents: Buffer | ||
* ) {} | ||
* ``` | ||
*/ | ||
export const RawBody = createMetadataDecorator({ | ||
types: ['class', 'method'], | ||
setter: ( | ||
config: { | ||
/** | ||
* Pass the raw body through to the handler or | ||
* just to keep the raw body in addition to regular content parsing. | ||
*/ | ||
passthrough?: boolean; | ||
/** | ||
* The allowed content types. | ||
* Only applicable if passthrough is true. | ||
* Defaults to '*' | ||
*/ | ||
allowContentTypes?: Many<string> | RegExp; | ||
} = {}, | ||
) => config, | ||
}); |
Oops, something went wrong.