forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp2.js
39 lines (35 loc) · 744 Bytes
/
http2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const fs = require('node:fs')
const path = require('node:path')
const fastify = require('../fastify')({
http2: true,
https: {
key: fs.readFileSync(path.join(__dirname, '../test/https/fastify.key')),
cert: fs.readFileSync(path.join(__dirname, '../test/https/fastify.cert'))
},
logger: true
})
const opts = {
schema: {
response: {
'2xx': {
type: 'object',
properties: {
hello: {
type: 'string'
}
}
}
}
}
}
fastify
.get('/', opts, function (req, reply) {
reply.header('Content-Type', 'application/json').code(200)
reply.send({ hello: 'world' })
})
fastify.listen({ port: 3000 }, err => {
if (err) {
throw err
}
})