UNPKG

744 BJavaScriptView Raw
1'use strict'
2
3const fs = require('node:fs')
4const path = require('node: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 logger: true
12})
13
14const opts = {
15 schema: {
16 response: {
17 '2xx': {
18 type: 'object',
19 properties: {
20 hello: {
21 type: 'string'
22 }
23 }
24 }
25 }
26 }
27}
28
29fastify
30 .get('/', opts, function (req, reply) {
31 reply.header('Content-Type', 'application/json').code(200)
32 reply.send({ hello: 'world' })
33 })
34
35fastify.listen({ port: 3000 }, err => {
36 if (err) {
37 throw err
38 }
39})