-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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 #11992 from rich-w-lee/feature/fastify-route-config
feat(fastify): supporting fastify route config
- Loading branch information
Showing
8 changed files
with
90 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const FASTIFY_ROUTE_CONFIG_METADATA = '__fastify_route_config__'; |
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 @@ | ||
export * from './route-config.decorator'; |
8 changes: 8 additions & 0 deletions
8
packages/platform-fastify/decorators/route-config.decorator.ts
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,8 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
import { FASTIFY_ROUTE_CONFIG_METADATA } from '../constants'; | ||
|
||
/** | ||
* @param config See {@link https://fastify.dev/docs/latest/Reference/Routes/#config} | ||
*/ | ||
export const RouteConfig = (config: any) => | ||
SetMetadata(FASTIFY_ROUTE_CONFIG_METADATA, config); |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
export * from './adapters'; | ||
export * from './interfaces'; | ||
export * from './decorators'; |
17 changes: 17 additions & 0 deletions
17
packages/platform-fastify/test/decorators/router-config.decorator.spec.ts
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,17 @@ | ||
import { expect } from 'chai'; | ||
import { FASTIFY_ROUTE_CONFIG_METADATA } from '../../constants'; | ||
import { RouteConfig } from '../../decorators/route-config.decorator'; | ||
|
||
describe('@RouteConfig', () => { | ||
const routeConfig = { testKey: 'testValue' }; | ||
class Test { | ||
config; | ||
@RouteConfig(routeConfig) | ||
public static test() {} | ||
} | ||
|
||
it('should enhance method with expected fastify route config', () => { | ||
const path = Reflect.getMetadata(FASTIFY_ROUTE_CONFIG_METADATA, Test.test); | ||
expect(path).to.be.eql(routeConfig); | ||
}); | ||
}); |