@fastify/reply-from 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +6 -51
- package/README.md +13 -2
- package/index.d.ts +1 -0
- package/index.js +7 -3
- package/package.json +18 -21
- package/test/disable-request-logging.js +159 -0
- package/test/index.test-d.ts +1 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,60 +1,15 @@
|
|
|
1
1
|
name: CI
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
on:
|
|
3
4
|
push:
|
|
4
5
|
paths-ignore:
|
|
5
|
-
- docs/**
|
|
6
|
+
- 'docs/**'
|
|
6
7
|
- '*.md'
|
|
7
8
|
pull_request:
|
|
8
9
|
paths-ignore:
|
|
9
|
-
- docs/**
|
|
10
|
+
- 'docs/**'
|
|
10
11
|
- '*.md'
|
|
12
|
+
|
|
11
13
|
jobs:
|
|
12
14
|
test:
|
|
13
|
-
|
|
14
|
-
strategy:
|
|
15
|
-
matrix:
|
|
16
|
-
node-version:
|
|
17
|
-
- 14
|
|
18
|
-
- 16
|
|
19
|
-
- 18
|
|
20
|
-
os:
|
|
21
|
-
- macos-latest
|
|
22
|
-
- ubuntu-latest
|
|
23
|
-
- windows-latest
|
|
24
|
-
steps:
|
|
25
|
-
- uses: actions/checkout@v3
|
|
26
|
-
- name: Use Node.js
|
|
27
|
-
uses: actions/setup-node@v3
|
|
28
|
-
with:
|
|
29
|
-
node-version: ${{ matrix.node-version }}
|
|
30
|
-
- name: Install Dependencies
|
|
31
|
-
run: |
|
|
32
|
-
npm install --ignore-scripts
|
|
33
|
-
- name: Run Tests
|
|
34
|
-
run: |
|
|
35
|
-
npm run test:ci
|
|
36
|
-
- name: Coveralls Parallel
|
|
37
|
-
uses: coverallsapp/github-action@1.1.3
|
|
38
|
-
with:
|
|
39
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
40
|
-
parallel: true
|
|
41
|
-
flag-name: run-${{ matrix.node-version }}-${{ matrix.os }}
|
|
42
|
-
coverage:
|
|
43
|
-
needs: test
|
|
44
|
-
runs-on: ubuntu-latest
|
|
45
|
-
steps:
|
|
46
|
-
- name: Coveralls Finished
|
|
47
|
-
uses: coverallsapp/github-action@1.1.3
|
|
48
|
-
with:
|
|
49
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
50
|
-
parallel-finished: true
|
|
51
|
-
automerge:
|
|
52
|
-
needs: test
|
|
53
|
-
runs-on: ubuntu-latest
|
|
54
|
-
permissions:
|
|
55
|
-
pull-requests: write
|
|
56
|
-
contents: write
|
|
57
|
-
steps:
|
|
58
|
-
- uses: fastify/github-action-merge-dependabot@v3.1.4
|
|
59
|
-
with:
|
|
60
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
|
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
[](https://www.npmjs.com/package/@fastify/reply-from)
|
|
5
|
-
[](https://snyk.io/test/github/fastify/fastify-reply-from)
|
|
6
|
-
[](https://coveralls.io/github/fastify/fastify-reply-from?branch=master)
|
|
7
5
|
[](https://standardjs.com/)
|
|
8
6
|
|
|
9
7
|
Fastify plugin to forward the current HTTP request to another server.
|
|
@@ -175,6 +173,19 @@ proxy.register(require('@fastify/reply-from'), {
|
|
|
175
173
|
})
|
|
176
174
|
```
|
|
177
175
|
|
|
176
|
+
#### `disableRequestLogging`
|
|
177
|
+
|
|
178
|
+
By default package will issue log messages when a request is received. By setting this option to true, these log messages will be disabled.
|
|
179
|
+
|
|
180
|
+
Default for `disableRequestLogging` will be `false`. To disable the log messages set `disableRequestLogging` to `true`.
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
proxy.register(require('@fastify/reply-from'), {
|
|
184
|
+
base: 'http://localhost:3001/',
|
|
185
|
+
disableRequestLogging: true // request log messages will be disabled
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
178
189
|
#### `cacheURLs`
|
|
179
190
|
|
|
180
191
|
The number of parsed URLs that will be cached. Default: `100`.
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ module.exports = fp(function from (fastify, opts, next) {
|
|
|
33
33
|
base,
|
|
34
34
|
undici: opts.undici
|
|
35
35
|
})
|
|
36
|
+
const disableRequestLogging = opts.disableRequestLogging || false
|
|
36
37
|
|
|
37
38
|
fastify.decorateReply('from', function (source, opts) {
|
|
38
39
|
opts = opts || {}
|
|
@@ -120,7 +121,7 @@ module.exports = fp(function from (fastify, opts, next) {
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
this.request.log.info({ source }, 'fetching from remote server')
|
|
124
|
+
!disableRequestLogging && this.request.log.info({ source }, 'fetching from remote server')
|
|
124
125
|
|
|
125
126
|
const requestHeaders = rewriteRequestHeaders(req, headers)
|
|
126
127
|
const contentLength = requestHeaders['content-length']
|
|
@@ -145,7 +146,7 @@ module.exports = fp(function from (fastify, opts, next) {
|
|
|
145
146
|
}
|
|
146
147
|
return
|
|
147
148
|
}
|
|
148
|
-
this.request.log.info('response received')
|
|
149
|
+
!disableRequestLogging && this.request.log.info('response received')
|
|
149
150
|
if (sourceHttp2) {
|
|
150
151
|
copyHeaders(
|
|
151
152
|
rewriteHeaders(stripHttp1ConnectionHeaders(res.headers), req),
|
|
@@ -179,7 +180,10 @@ module.exports = fp(function from (fastify, opts, next) {
|
|
|
179
180
|
})
|
|
180
181
|
|
|
181
182
|
next()
|
|
182
|
-
},
|
|
183
|
+
}, {
|
|
184
|
+
fastify: '4.x',
|
|
185
|
+
name: '@fastify/reply-from'
|
|
186
|
+
})
|
|
183
187
|
|
|
184
188
|
function getQueryString (search, reqUrl, opts) {
|
|
185
189
|
if (typeof opts.queryString === 'function') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/reply-from",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "forward your HTTP request to another server, for fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -26,40 +26,37 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/fastify/fastify-reply-from/issues"
|
|
28
28
|
},
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=12.18"
|
|
31
|
-
},
|
|
32
29
|
"homepage": "https://github.com/fastify/fastify-reply-from#readme",
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@fastify/formbody": "^7.0.
|
|
35
|
-
"@fastify/multipart": "^7.
|
|
36
|
-
"@sinonjs/fake-timers": "^9.
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
"@types/tap": "^15.0.
|
|
39
|
-
"fastify": "^4.0.
|
|
31
|
+
"@fastify/formbody": "^7.0.1",
|
|
32
|
+
"@fastify/multipart": "^7.1.0",
|
|
33
|
+
"@sinonjs/fake-timers": "^9.1.2",
|
|
34
|
+
"@types/node": "^18.0.0",
|
|
35
|
+
"@types/tap": "^15.0.7",
|
|
36
|
+
"fastify": "^4.0.2",
|
|
40
37
|
"form-data": "^4.0.0",
|
|
41
38
|
"got": "^11.8.2",
|
|
42
39
|
"h2url": "^0.2.0",
|
|
43
|
-
"msgpack5": "^6.0.
|
|
44
|
-
"nock": "^13.
|
|
40
|
+
"msgpack5": "^6.0.1",
|
|
41
|
+
"nock": "^13.2.6",
|
|
45
42
|
"pre-commit": "^1.2.2",
|
|
46
43
|
"proxyquire": "^2.1.3",
|
|
47
|
-
"simple-get": "^4.0.
|
|
44
|
+
"simple-get": "^4.0.1",
|
|
48
45
|
"snazzy": "^9.0.0",
|
|
49
|
-
"split2": "^4.
|
|
46
|
+
"split2": "^4.1.0",
|
|
50
47
|
"standard": "^17.0.0",
|
|
51
|
-
"tap": "^16.
|
|
52
|
-
"tsd": "^0.
|
|
53
|
-
"typescript": "^4.3
|
|
48
|
+
"tap": "^16.2.0",
|
|
49
|
+
"tsd": "^0.21.0",
|
|
50
|
+
"typescript": "^4.7.3"
|
|
54
51
|
},
|
|
55
52
|
"dependencies": {
|
|
56
53
|
"end-of-stream": "^1.4.4",
|
|
57
|
-
"fastify-plugin": "^3.0.
|
|
54
|
+
"fastify-plugin": "^3.0.1",
|
|
58
55
|
"http-errors": "^2.0.0",
|
|
59
56
|
"pump": "^3.0.0",
|
|
60
|
-
"semver": "^7.3.
|
|
61
|
-
"tiny-lru": "^8.0.
|
|
62
|
-
"undici": "^5.
|
|
57
|
+
"semver": "^7.3.7",
|
|
58
|
+
"tiny-lru": "^8.0.2",
|
|
59
|
+
"undici": "^5.5.1"
|
|
63
60
|
},
|
|
64
61
|
"tsd": {
|
|
65
62
|
"directory": "test"
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap')
|
|
4
|
+
const Fastify = require('fastify')
|
|
5
|
+
const From = require('..')
|
|
6
|
+
const http = require('http')
|
|
7
|
+
const get = require('simple-get').concat
|
|
8
|
+
const split = require('split2')
|
|
9
|
+
|
|
10
|
+
const target = http.createServer((req, res) => {
|
|
11
|
+
t.pass('request proxied')
|
|
12
|
+
t.equal(req.method, 'GET')
|
|
13
|
+
t.equal(req.url, '/')
|
|
14
|
+
t.equal(req.headers.connection, 'keep-alive')
|
|
15
|
+
res.statusCode = 205
|
|
16
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
17
|
+
res.setHeader('x-my-header', 'hello!')
|
|
18
|
+
res.end('hello world')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
t.test('use a custom instance of \'undici\'', async t => {
|
|
22
|
+
t.teardown(target.close.bind(target))
|
|
23
|
+
|
|
24
|
+
await new Promise((resolve, reject) => target.listen({ port: 0 }, err => err ? reject(err) : resolve()))
|
|
25
|
+
|
|
26
|
+
t.test('disableRequestLogging is set to true', t => {
|
|
27
|
+
t.plan(10)
|
|
28
|
+
const logStream = split(JSON.parse)
|
|
29
|
+
const instance = Fastify({
|
|
30
|
+
logger: {
|
|
31
|
+
level: 'info',
|
|
32
|
+
stream: logStream
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
t.teardown(instance.close.bind(instance))
|
|
36
|
+
instance.register(From, {
|
|
37
|
+
base: `http://localhost:${target.address().port}`,
|
|
38
|
+
disableRequestLogging: true
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
instance.get('/', (request, reply) => {
|
|
42
|
+
reply.from()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
logStream.on('data', (log) => {
|
|
46
|
+
if (
|
|
47
|
+
log.level === 30 &&
|
|
48
|
+
(
|
|
49
|
+
!log.msg.match('response received') ||
|
|
50
|
+
!log.msg.match('fetching from remote server')
|
|
51
|
+
)
|
|
52
|
+
) {
|
|
53
|
+
t.pass('request log message does not logged')
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
instance.listen({ port: 0 }, (err) => {
|
|
58
|
+
t.error(err)
|
|
59
|
+
|
|
60
|
+
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
|
|
61
|
+
t.error(err)
|
|
62
|
+
t.equal(res.headers['content-type'], 'text/plain')
|
|
63
|
+
t.equal(res.headers['x-my-header'], 'hello!')
|
|
64
|
+
t.equal(res.statusCode, 205)
|
|
65
|
+
t.equal(data.toString(), 'hello world')
|
|
66
|
+
t.end()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
t.test('disableRequestLogging is set to false', t => {
|
|
72
|
+
t.plan(8)
|
|
73
|
+
const logStream = split(JSON.parse)
|
|
74
|
+
const instance = Fastify({
|
|
75
|
+
logger: {
|
|
76
|
+
level: 'info',
|
|
77
|
+
stream: logStream
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
t.teardown(instance.close.bind(instance))
|
|
81
|
+
instance.register(From, {
|
|
82
|
+
base: `http://localhost:${target.address().port}`,
|
|
83
|
+
disableRequestLogging: false
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
instance.get('/', (request, reply) => {
|
|
87
|
+
reply.from()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
logStream.on('data', (log) => {
|
|
91
|
+
if (
|
|
92
|
+
log.level === 30 &&
|
|
93
|
+
(
|
|
94
|
+
log.msg.match('response received') ||
|
|
95
|
+
log.msg.match('fetching from remote server')
|
|
96
|
+
)
|
|
97
|
+
) {
|
|
98
|
+
t.pass('request log message does not logged')
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
instance.listen({ port: 0 }, (err) => {
|
|
103
|
+
t.error(err)
|
|
104
|
+
|
|
105
|
+
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
|
|
106
|
+
t.error(err)
|
|
107
|
+
t.equal(res.headers['content-type'], 'text/plain')
|
|
108
|
+
t.equal(res.headers['x-my-header'], 'hello!')
|
|
109
|
+
t.equal(res.statusCode, 205)
|
|
110
|
+
t.equal(data.toString(), 'hello world')
|
|
111
|
+
t.end()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
t.test('disableRequestLogging is not defined', t => {
|
|
117
|
+
t.plan(8)
|
|
118
|
+
const logStream = split(JSON.parse)
|
|
119
|
+
const instance = Fastify({
|
|
120
|
+
logger: {
|
|
121
|
+
level: 'info',
|
|
122
|
+
stream: logStream
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
t.teardown(instance.close.bind(instance))
|
|
126
|
+
instance.register(From, {
|
|
127
|
+
base: `http://localhost:${target.address().port}`
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
instance.get('/', (request, reply) => {
|
|
131
|
+
reply.from()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
logStream.on('data', (log) => {
|
|
135
|
+
if (
|
|
136
|
+
log.level === 30 &&
|
|
137
|
+
(
|
|
138
|
+
log.msg.match('response received') ||
|
|
139
|
+
log.msg.match('fetching from remote server')
|
|
140
|
+
)
|
|
141
|
+
) {
|
|
142
|
+
t.pass('request log message does not logged')
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
instance.listen({ port: 0 }, (err) => {
|
|
147
|
+
t.error(err)
|
|
148
|
+
|
|
149
|
+
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
|
|
150
|
+
t.error(err)
|
|
151
|
+
t.equal(res.headers['content-type'], 'text/plain')
|
|
152
|
+
t.equal(res.headers['x-my-header'], 'hello!')
|
|
153
|
+
t.equal(res.statusCode, 205)
|
|
154
|
+
t.equal(data.toString(), 'hello world')
|
|
155
|
+
t.end()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
})
|
package/test/index.test-d.ts
CHANGED