Skip to content

Commit 94b8595

Browse files
authored
Update to Fastify v4 (#247)
* Update to Fastify v4 Signed-off-by: Matteo Collina <hello@matteocollina.com> * dropped old nodes Signed-off-by: Matteo Collina <hello@matteocollina.com> * support node v18 in tests Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 9837562 commit 94b8595

File tree

8 files changed

+45
-43
lines changed

8 files changed

+45
-43
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
strategy:
1515
matrix:
1616
node-version:
17-
- 12
1817
- 14
1918
- 16
19+
- 18
2020
os:
2121
- macos-latest
2222
- ubuntu-latest

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ async function httpProxy (fastify, opts) {
204204
}
205205

206206
httpProxy[Symbol.for('plugin-meta')] = {
207-
fastify: '^3.0.0',
208-
name: 'fastify-http-proxy'
207+
fastify: '^4.0.0',
208+
name: '@fastify/http-proxy'
209209
}
210210

211211
module.exports = httpProxy

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
"homepage": "https://github.com/fastify/fastify-http-proxy#readme",
2929
"devDependencies": {
3030
"@fastify/pre-commit": "^2.0.2",
31-
"@fastify/websocket": "^5.0.0",
31+
"@fastify/websocket": "^6.0.1",
3232
"@types/node": "^17.0.8",
3333
"@types/ws": "^8.2.2",
3434
"@typescript-eslint/eslint-plugin": "^5.9.1",
3535
"@typescript-eslint/parser": "^5.9.1",
3636
"express": "^4.17.2",
3737
"express-http-proxy": "^1.6.3",
3838
"fast-proxy": "^2.1.0",
39-
"fastify": "^3.25.3",
39+
"fastify": "^4.0.0-rc.2",
4040
"got": "^11.8.3",
4141
"http-errors": "^2.0.0",
4242
"http-proxy": "^1.18.1",
@@ -48,10 +48,11 @@
4848
"standard": "^17.0.0",
4949
"tap": "^16.0.0",
5050
"tsd": "^0.20.0",
51-
"typescript": "^4.5.4"
51+
"typescript": "^4.5.4",
52+
"why-is-node-running": "^2.2.2"
5253
},
5354
"dependencies": {
54-
"@fastify/reply-from": "^7.0.0",
55+
"@fastify/reply-from": "^8.0.0",
5556
"ws": "^8.4.2"
5657
},
5758
"tsd": {

test/socket.io.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('proxy socket.io', async t => {
2828
websocket: true
2929
})
3030

31-
await srvProxy.listen(0)
31+
await srvProxy.listen({ port: 0 })
3232

3333
srvSocket.on('connection', socket => {
3434
socket.on('hello', data => {

test/test.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ async function run () {
3838
return 'this is never received'
3939
})
4040

41-
await origin.listen(0)
41+
await origin.listen({ port: 0 })
4242

43-
teardown(origin.close.bind(origin))
43+
teardown(() => origin.close())
4444

4545
test('basic proxy', async t => {
4646
const server = Fastify()
4747
server.register(proxy, {
4848
upstream: `http://localhost:${origin.server.address().port}`
4949
})
5050

51-
await server.listen(0)
51+
await server.listen({ port: 0 })
5252
t.teardown(server.close.bind(server))
5353

5454
const resultRoot = await got(
@@ -73,7 +73,7 @@ async function run () {
7373
}
7474
})
7575

76-
await server.listen(0)
76+
await server.listen({ port: 0 })
7777
t.teardown(server.close.bind(server))
7878

7979
const resultRoot = await got(
@@ -93,7 +93,7 @@ async function run () {
9393
upstream: `http://localhost:${origin.server.address().port}`
9494
})
9595

96-
await server.listen(0)
96+
await server.listen({ port: 0 })
9797
t.teardown(server.close.bind(server))
9898

9999
const {
@@ -119,7 +119,7 @@ async function run () {
119119
}
120120
})
121121

122-
await server.listen(0)
122+
await server.listen({ port: 0 })
123123
t.teardown(server.close.bind(server))
124124

125125
const {
@@ -153,7 +153,7 @@ async function run () {
153153
prefix: '/my-prefix'
154154
})
155155

156-
await server.listen(0)
156+
await server.listen({ port: 0 })
157157
t.teardown(server.close.bind(server))
158158

159159
const resultRoot = await got(
@@ -184,7 +184,7 @@ async function run () {
184184
}
185185
})
186186

187-
await server.listen(0)
187+
await server.listen({ port: 0 })
188188
t.teardown(server.close.bind(server))
189189

190190
const resultRoot = await got(
@@ -209,7 +209,7 @@ async function run () {
209209
upstream: `http://localhost:${origin.server.address().port}`
210210
})
211211

212-
await server.listen(0)
212+
await server.listen({ port: 0 })
213213
t.teardown(server.close.bind(server))
214214

215215
const resultRoot = await got(
@@ -234,7 +234,7 @@ async function run () {
234234
}
235235
})
236236

237-
await server.listen(0)
237+
await server.listen({ port: 0 })
238238
t.teardown(server.close.bind(server))
239239

240240
const resultRoot = await got(
@@ -259,7 +259,7 @@ async function run () {
259259
}
260260
})
261261

262-
await server.listen(0)
262+
await server.listen({ port: 0 })
263263
t.teardown(server.close.bind(server))
264264

265265
await got(
@@ -281,7 +281,7 @@ async function run () {
281281
}
282282
})
283283

284-
await server.listen(0)
284+
await server.listen({ port: 0 })
285285
t.teardown(server.close.bind(server))
286286

287287
let errored = false
@@ -326,7 +326,7 @@ async function run () {
326326
}
327327
})
328328

329-
await server.listen(0)
329+
await server.listen({ port: 0 })
330330
t.teardown(server.close.bind(server))
331331

332332
let errored = false
@@ -346,7 +346,7 @@ async function run () {
346346
return 'this is root for origin2'
347347
})
348348

349-
await origin2.listen(0)
349+
await origin2.listen({ port: 0 })
350350

351351
const proxyServer = Fastify()
352352

@@ -362,7 +362,7 @@ async function run () {
362362
prefix: '/api2'
363363
})
364364

365-
await proxyServer.listen(0)
365+
await proxyServer.listen({ port: 0 })
366366

367367
t.teardown(() => {
368368
origin2.close()
@@ -391,7 +391,7 @@ async function run () {
391391
}
392392
})
393393

394-
await proxyServer.listen(0)
394+
await proxyServer.listen({ port: 0 })
395395

396396
t.teardown(() => {
397397
proxyServer.close()
@@ -412,7 +412,7 @@ async function run () {
412412
rewritePrefix: '/api2'
413413
})
414414

415-
await proxyServer.listen(0)
415+
await proxyServer.listen({ port: 0 })
416416

417417
t.teardown(() => {
418418
proxyServer.close()
@@ -432,7 +432,7 @@ async function run () {
432432
prefix: '/api'
433433
})
434434

435-
await proxyServer.listen(0)
435+
await proxyServer.listen({ port: 0 })
436436

437437
t.teardown(() => {
438438
proxyServer.close()
@@ -472,7 +472,7 @@ async function run () {
472472
}
473473
})
474474

475-
await proxyServer.listen(0)
475+
await proxyServer.listen({ port: 0 })
476476

477477
t.teardown(() => {
478478
proxyServer.close()
@@ -493,7 +493,7 @@ async function run () {
493493
undici: true
494494
})
495495

496-
await proxyServer.listen(0)
496+
await proxyServer.listen({ port: 0 })
497497

498498
t.teardown(() => {
499499
proxyServer.close()
@@ -522,7 +522,7 @@ async function run () {
522522
}
523523
})
524524

525-
await server.listen(0)
525+
await server.listen({ port: 0 })
526526
t.teardown(server.close.bind(server))
527527

528528
try {
@@ -545,7 +545,7 @@ async function run () {
545545
httpMethods: ['POST']
546546
})
547547

548-
await server.listen(0)
548+
await server.listen({ port: 0 })
549549
t.teardown(server.close.bind(server))
550550

551551
const resultRoot = await got(
@@ -596,7 +596,7 @@ async function run () {
596596
constraints: { testConstraint: 'valid-value' }
597597
})
598598

599-
await server.listen(0)
599+
await server.listen({ port: 0 })
600600
t.teardown(server.close.bind(server))
601601
await got(`http://localhost:${server.server.address().port}/a`, {
602602
headers: {
@@ -637,7 +637,7 @@ async function run () {
637637
constraints: { testConstraint: 'with-proxy' }
638638
})
639639

640-
await server.listen(0)
640+
await server.listen({ port: 0 })
641641
t.teardown(server.close.bind(server))
642642

643643
const resultProxied = await got(`http://localhost:${server.server.address().port}/a`, {
@@ -664,17 +664,18 @@ async function run () {
664664
appServer.get('/second-service/foo', async (request, reply) => {
665665
return `Hello World (foo) - lang = ${request.query.lang}`
666666
})
667-
const address = await appServer.listen(0)
667+
const address = await appServer.listen({ port: 0 })
668+
console.log(address)
668669

669670
const proxyServer = Fastify()
670671
proxyServer.register(proxy, {
671672
upstream: `${address}/second-service`,
672673
prefix: '/second-service'
673674
})
674-
const proxyAddress = await proxyServer.listen(0)
675+
const proxyAddress = await proxyServer.listen({ port: 0 })
675676

676-
t.teardown(appServer.close.bind(appServer))
677677
t.teardown(proxyServer.close.bind(proxyServer))
678+
t.teardown(appServer.close.bind(appServer))
678679

679680
const resultRoot = await got(
680681
`${proxyAddress}/second-service?lang=en`

test/websocket.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ test('basic websocket proxy', async (t) => {
2626
})
2727
})
2828

29-
await promisify(origin.listen.bind(origin))(0)
29+
await promisify(origin.listen.bind(origin))({ port: 0 })
3030

3131
const server = Fastify()
3232
server.register(proxy, {
3333
upstream: `ws://localhost:${origin.address().port}`,
3434
websocket: true
3535
})
3636

37-
await server.listen(0)
37+
await server.listen({ port: 0 })
3838
t.teardown(server.close.bind(server))
3939

4040
const options = { headers: { cookie: cookieValue } }
@@ -58,14 +58,14 @@ test('basic websocket proxy', async (t) => {
5858

5959
test('captures errors on start', async (t) => {
6060
const app = Fastify()
61-
await app.listen(0)
61+
await app.listen({ port: 0 })
6262

6363
const app2 = Fastify()
6464
app2.register(proxy, { upstream: 'ws://localhost', websocket: true })
6565

6666
const appPort = app.server.address().port
6767

68-
await t.rejects(app2.listen(appPort), /EADDRINUSE/)
68+
await t.rejects(app2.listen({ port: appPort }), /EADDRINUSE/)
6969

7070
t.teardown(app.close.bind(app))
7171
t.teardown(app2.close.bind(app2))

test/ws-prefix-rewrite-core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function proxyServer (t, backendURL, backendPath, proxyOptions, wrapperOpt
3030
await registerProxy(frontend)
3131
}
3232

33-
return [frontend, await frontend.listen(0)]
33+
return [frontend, await frontend.listen({ port: 0, host: '127.0.0.1' })]
3434
}
3535

3636
async function processRequest (t, frontendURL, path, expected) {
@@ -84,7 +84,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions },
8484

8585
t.teardown(() => backend.close())
8686

87-
const backendURL = await backend.listen(0)
87+
const backendURL = await backend.listen({ port: 0, host: '127.0.0.1' })
8888

8989
const [frontend, frontendURL] = await proxyServer(t, backendURL, backendPath, proxyOptions, wrapperOptions)
9090

test/ws-prefix-rewrite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function proxyServer (t, backendURL, backendPath, proxyOptions, wrapperOpt
2828
await registerProxy(frontend)
2929
}
3030

31-
return [frontend, await frontend.listen(0)]
31+
return [frontend, await frontend.listen({ port: 0 })]
3232
}
3333

3434
async function processRequest (t, frontendURL, path, expected) {
@@ -80,7 +80,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions },
8080
}
8181
})
8282

83-
const backendURL = await backend.listen(0)
83+
const backendURL = await backend.listen({ port: 0 })
8484

8585
const [frontend, frontendURL] = await proxyServer(t, backendURL, backendPath, proxyOptions, wrapperOptions)
8686

0 commit comments

Comments
 (0)