UNPKG

707 BJavaScriptView Raw
1'use strict'
2
3const fastify = require('../fastify')({ logger: true })
4
5const schema = {
6 schema: {
7 response: {
8 200: {
9 type: 'object',
10 properties: {
11 hello: {
12 type: 'string'
13 }
14 }
15 }
16 }
17 }
18}
19
20function result () {
21 return Promise.resolve({ hello: 'world' })
22}
23
24fastify
25 .get('/await', schema, async function (req, reply) {
26 reply.header('Content-Type', 'application/json').code(200)
27 return result()
28 })
29 .get('/', schema, async function (req, reply) {
30 reply.header('Content-Type', 'application/json').code(200)
31 return { hello: 'world' }
32 })
33
34fastify.listen({ port: 3000 }, err => {
35 if (err) {
36 throw err
37 }
38})