UNPKG

1.04 kBJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const fs = require('fs')
6const path = require('path')
7const Fastify = require('../..')
8const h2url = require('h2url')
9const msg = { hello: 'world' }
10
11var fastify
12try {
13 fastify = Fastify({
14 http2: true,
15 https: {
16 key: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.key')),
17 cert: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.cert'))
18 }
19 })
20 t.pass('Key/cert successfully loaded')
21} catch (e) {
22 t.fail('Key/cert loading failed', e)
23}
24
25fastify.get('/', function (req, reply) {
26 reply.code(200).send(msg)
27})
28
29fastify.listen(0, err => {
30 t.error(err)
31 fastify.server.unref()
32
33 test('https get request', async (t) => {
34 t.plan(3)
35
36 const url = `https://localhost:${fastify.server.address().port}`
37 const res = await h2url.concat({ url })
38
39 t.strictEqual(res.headers[':status'], 200)
40 t.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length)
41 t.deepEqual(JSON.parse(res.body), msg)
42 })
43})