fastify.route({ method: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT','OPTIONS'], url: '/v2/*', handler: async function(request, reply){ await mockApiImplementation(request, reply); } });
fastify.get('/', { schema }, ({ query }, res) => { const { number1, number2 } = query const calculation = sum(number1, number2) return res.send({ "hey": "ho! livereload" }) })
fastify.addContentTypeParser('application/x-protobuf', function (req, done) { var data = '' req.on('data', chunk => { data += chunk }) req.on('end', () => { done(messages.PushRequest.decode(data)) }) })
fp(async function onResponse (fastify, opts) { fastify.addHook('onResponse', async (request, reply) => { // Notice: the next callback is not available when using async/await // or returning a Promise. If you do invoke a next callback in this // situation unexpected behavior may occur, e.g. duplicate invocation // of handlers. }) // fastify.addHook('onResponse', (request, reply, next) => { // next() // }) })
fastify.listen(config.api.port, config.api.host, (err, address) => { if (err) { reject(err); } console.log('\n'); console.log(`${chalk.blue('API Started at:')} ${address}`); resolve(); });
test('support works standalone', async (t) => { const fastify = Fastify() fastify.register(Support) await fastify.ready() t.equal(fastify.someSupport(), 'here support') })
fastify.route({ method: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT','OPTIONS'], url: '/pet*', handler: async function(request, reply){ await mockApiImplementation(request, reply); } });
fp(async function preValidation (fastify, opts) { fastify.addHook('preValidation', async (request, reply) => { // Notice: the next callback is not available when using async/await // or returning a Promise. If you do invoke a next callback in this // situation unexpected behavior may occur, e.g. duplicate invocation // of handlers. }) // fastify.addHook('preValidation', (request, reply, next) => { // next() // }) })
fp(async function preValidation (fastify, opts) { fastify.addHook('preValidation', async (request, reply) => { // Notice: the next callback is not available when using async/await // or returning a Promise. If you do invoke a next callback in this // situation unexpected behavior may occur, e.g. duplicate invocation // of handlers. }) // fastify.addHook('preValidation', (request, reply, next) => { // next() // }) })
fp(async function preParsing (fastify, opts) { fastify.addHook('preParsing', async (request, reply) => { // Notice: the next callback is not available when using async/await // or returning a Promise. If you do invoke a next callback in this // situation unexpected behavior may occur, e.g. duplicate invocation // of handlers. }) // fastify.addHook('preParsing', (request, reply, next) => { // next() // }) })