-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.controller.ts
47 lines (42 loc) · 1.31 KB
/
app.controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Controller, Get, Req, Version } from '@nestjs/common';
import { RouteConfig, RouteConstraints } from '@nestjs/platform-fastify';
@Controller()
export class AppController {
// Using NestJS API versioning: https://docs.nestjs.com/techniques/versioning
@Get('/greet')
@Version('1')
@RouteConfig({ output: 'Hello world!' })
greetV1(@Req() req) {
return { msg: req.routeOptions.config.output, version: 'v1' };
}
// Using Fastify version constraints: https://fastify.dev/docs/latest/Reference/Routes/#version-constraints
@Get('/greet')
@RouteConstraints({
version: 'v2',
})
greetV2(@Req() req) {
return { msg: 'HELLO WORLD!', version: 'v2' };
}
// Using NestJS API versioning and Fastify host constraints: https://fastify.dev/docs/latest/Reference/Routes/#host-constraints
@Get('/greet')
@Version('v3')
@RouteConstraints({
host: 'de.example.com',
})
greetDEHosts() {
return { msg: 'Hello welt!', version: 'v3' };
}
// Using Fastify host constraints: https://fastify.dev/docs/latest/Reference/Routes/#host-constraints
@Get('/greet')
@RouteConstraints({
host: 'ar.example.com',
})
greetArHosts() {
return { msg: 'آهلا بالعالم' };
}
// Not using any config
@Get('/greet-everyone')
greetEveryone() {
return { msg: 'Hello world!' };
}
}