Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Controller({
route: '/request',
type: ControllerType.REQUEST
})
class RequestController extends AbstractController {
private callsCount = 0;
@GET('/index')
async indexHandler() {
this.instance.log.info('Handled request to /request/index');
this.callsCount++;
return 'Request controller: index handler, calls count: ' + this.callsCount;
}
@Hook('onSend')
async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
reply.header('X-Powered-By', 'nodejs');
}
}
export = RequestController;
import { FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, ServerResponse } from 'http';
import { Controller, GET, Hook } from 'fastify-decorators';
@Controller('/ctrl')
export default class SingletonController {
private callsCount = 0;
@GET('/index')
async index() {
this.callsCount++;
return 'Singleton controller: index handler, calls count: ' + this.callsCount;
}
@Hook('onSend')
async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
reply.header('X-Powered-By', 'nodejs');
}
}
schema: {
response: {
200: {
properties: {
message: {type: 'string'}
}
}
}
}
}
})
async test(request: FastifyRequest, reply: FastifyReply) {
return {message: this.message};
}
@Hook('onSend')
async hidePoweredBy(request: FastifyRequest, reply: FastifyReply) {
reply.header('X-Powered-By', 'nodejs');
}
private message: string = 'Controller works!';
}