Skip to content

Commit 3c0b5b2

Browse files
allancalixmcollina
authored andcommitted
Replace basePath with prefix for Fastify v2 compatibility (#35)
* Replace deprecated basePath prop with prefix for v2 * Bump fastify version * Update README fastify version
1 parent dd46389 commit 3c0b5b2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This plugin can be used in a variety of circumstances, for example if you have t
1616

1717
## Requirements
1818

19-
Fastify ^1.8.0
19+
Fastify 2.x. See [this branch](https://github.com/fastify/fastify-http-proxy/tree/1.x) and related versions for Fastify 1.x compatibility.
2020

2121
## Install
2222

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = async function (fastify, opts) {
2828
function rewriteHeaders (headers) {
2929
const location = headers.location
3030
if (location) {
31-
headers.location = location.replace(rewritePrefix, fastify.basePath)
31+
headers.location = location.replace(rewritePrefix, fastify.prefix)
3232
}
3333
if (oldRewriteHeaders) {
3434
headers = oldRewriteHeaders(headers)
@@ -45,7 +45,7 @@ module.exports = async function (fastify, opts) {
4545

4646
function reply (request, reply) {
4747
var dest = request.req.url
48-
dest = dest.replace(this.basePath, rewritePrefix)
48+
dest = dest.replace(this.prefix, rewritePrefix)
4949
reply.from(dest || '/', replyOpts)
5050
}
5151
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"express": "^4.16.4",
2626
"express-http-proxy": "^1.5.0",
27-
"fastify": "^1.13.3",
27+
"fastify": "^2.0.0-rc.4",
2828
"got": "^9.5.0",
2929
"http-errors": "^1.7.1",
3030
"http-proxy": "^1.17.0",
@@ -36,7 +36,7 @@
3636
"tap": "^12.1.1"
3737
},
3838
"peerDependencies": {
39-
"fastify": "1.x"
39+
"fastify": "2.x"
4040
},
4141
"dependencies": {
4242
"fastify-reply-from": "^0.5.3"

0 commit comments

Comments
 (0)