@fastify/reply-from
Version:
forward your HTTP request to another server, for fastify
38 lines (31 loc) • 870 B
JavaScript
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('..')
const got = require('got')
test('http2 invalid target', async (t) => {
const instance = Fastify()
t.teardown(instance.close.bind(instance))
instance.get('/', (_request, reply) => {
reply.from()
})
instance.register(From, {
base: 'http://abc.xyz1',
http2: true
})
await instance.listen({ port: 0 })
try {
await got(`http://localhost:${instance.server.address().port}`)
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.same(JSON.parse(err.response.body), {
statusCode: 503,
code: 'FST_REPLY_FROM_SERVICE_UNAVAILABLE',
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})