You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					45 lines
				
				779 B
			
		
		
			
		
	
	
					45 lines
				
				779 B
			| 
											3 years ago
										 | 'use strict' | ||
|  | 
 | ||
|  | const fastify = require('../../fastify')({ logger: false }) | ||
|  | 
 | ||
|  | const opts = { | ||
|  |   schema: { | ||
|  |     response: { | ||
|  |       200: { | ||
|  |         type: 'object', | ||
|  |         properties: { | ||
|  |           hello: { | ||
|  |             type: 'string' | ||
|  |           } | ||
|  |         } | ||
|  |       } | ||
|  |     } | ||
|  |   } | ||
|  | } | ||
|  | 
 | ||
|  | function promiseFunction (resolve) { | ||
|  |   setImmediate(resolve) | ||
|  | } | ||
|  | 
 | ||
|  | async function asyncHook () { | ||
|  |   await new Promise(promiseFunction) | ||
|  | } | ||
|  | 
 | ||
|  | fastify | ||
|  |   .addHook('onRequest', asyncHook) | ||
|  |   .addHook('onRequest', asyncHook) | ||
|  |   .addHook('preHandler', asyncHook) | ||
|  |   .addHook('preHandler', asyncHook) | ||
|  |   .addHook('preHandler', asyncHook) | ||
|  |   .addHook('onSend', asyncHook) | ||
|  | 
 | ||
|  | fastify.get('/', opts, function (request, reply) { | ||
|  |   reply.send({ hello: 'world' }) | ||
|  | }) | ||
|  | 
 | ||
|  | fastify.listen(3000, function (err) { | ||
|  |   if (err) { | ||
|  |     throw err | ||
|  |   } | ||
|  | }) |