UNPKG

768 BJavaScriptView Raw
1'use strict'
2
3const fs = require('fs')
4const path = require('path')
5const fastify = require('../fastify')({
6 http2: true,
7 https: {
8 key: fs.readFileSync(path.join(__dirname, '../test/https/fastify.key')),
9 cert: fs.readFileSync(path.join(__dirname, '../test/https/fastify.cert'))
10 }
11})
12
13const opts = {
14 schema: {
15 response: {
16 '2xx': {
17 type: 'object',
18 properties: {
19 hello: {
20 type: 'string'
21 }
22 }
23 }
24 }
25 }
26}
27
28fastify
29 .get('/', opts, function (req, reply) {
30 reply.header('Content-Type', 'application/json').code(200)
31 reply.send({ hello: 'world' })
32 })
33
34fastify.listen(3000, err => {
35 if (err) throw err
36 console.log(`server listening on ${fastify.server.address().port}`)
37})