@fastify/reply-from
Advanced tools
| 'use strict' | ||
| const t = require('tap') | ||
| const Fastify = require('fastify') | ||
| const From = require('..') | ||
| const http = require('http') | ||
| const get = require('simple-get').concat | ||
| const split = require('split2') | ||
| const target = http.createServer((req, res) => { | ||
| t.pass('request proxied') | ||
| t.equal(req.method, 'GET') | ||
| t.equal(req.url, '/') | ||
| t.equal(req.headers.connection, 'keep-alive') | ||
| res.statusCode = 205 | ||
| res.setHeader('Content-Type', 'text/plain') | ||
| res.setHeader('x-my-header', 'hello!') | ||
| res.end('hello world') | ||
| }) | ||
| t.test('use a custom instance of \'undici\'', async t => { | ||
| t.teardown(target.close.bind(target)) | ||
| await new Promise((resolve, reject) => target.listen({ port: 0 }, err => err ? reject(err) : resolve())) | ||
| t.test('disableRequestLogging is set to true', t => { | ||
| t.plan(10) | ||
| const logStream = split(JSON.parse) | ||
| const instance = Fastify({ | ||
| logger: { | ||
| level: 'info', | ||
| stream: logStream | ||
| } | ||
| }) | ||
| t.teardown(instance.close.bind(instance)) | ||
| instance.register(From, { | ||
| base: `http://localhost:${target.address().port}`, | ||
| disableRequestLogging: true | ||
| }) | ||
| instance.get('/', (request, reply) => { | ||
| reply.from() | ||
| }) | ||
| logStream.on('data', (log) => { | ||
| if ( | ||
| log.level === 30 && | ||
| ( | ||
| !log.msg.match('response received') || | ||
| !log.msg.match('fetching from remote server') | ||
| ) | ||
| ) { | ||
| t.pass('request log message does not logged') | ||
| } | ||
| }) | ||
| instance.listen({ port: 0 }, (err) => { | ||
| t.error(err) | ||
| get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
| t.error(err) | ||
| t.equal(res.headers['content-type'], 'text/plain') | ||
| t.equal(res.headers['x-my-header'], 'hello!') | ||
| t.equal(res.statusCode, 205) | ||
| t.equal(data.toString(), 'hello world') | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
| t.test('disableRequestLogging is set to false', t => { | ||
| t.plan(8) | ||
| const logStream = split(JSON.parse) | ||
| const instance = Fastify({ | ||
| logger: { | ||
| level: 'info', | ||
| stream: logStream | ||
| } | ||
| }) | ||
| t.teardown(instance.close.bind(instance)) | ||
| instance.register(From, { | ||
| base: `http://localhost:${target.address().port}`, | ||
| disableRequestLogging: false | ||
| }) | ||
| instance.get('/', (request, reply) => { | ||
| reply.from() | ||
| }) | ||
| logStream.on('data', (log) => { | ||
| if ( | ||
| log.level === 30 && | ||
| ( | ||
| log.msg.match('response received') || | ||
| log.msg.match('fetching from remote server') | ||
| ) | ||
| ) { | ||
| t.pass('request log message does not logged') | ||
| } | ||
| }) | ||
| instance.listen({ port: 0 }, (err) => { | ||
| t.error(err) | ||
| get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
| t.error(err) | ||
| t.equal(res.headers['content-type'], 'text/plain') | ||
| t.equal(res.headers['x-my-header'], 'hello!') | ||
| t.equal(res.statusCode, 205) | ||
| t.equal(data.toString(), 'hello world') | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
| t.test('disableRequestLogging is not defined', t => { | ||
| t.plan(8) | ||
| const logStream = split(JSON.parse) | ||
| const instance = Fastify({ | ||
| logger: { | ||
| level: 'info', | ||
| stream: logStream | ||
| } | ||
| }) | ||
| t.teardown(instance.close.bind(instance)) | ||
| instance.register(From, { | ||
| base: `http://localhost:${target.address().port}` | ||
| }) | ||
| instance.get('/', (request, reply) => { | ||
| reply.from() | ||
| }) | ||
| logStream.on('data', (log) => { | ||
| if ( | ||
| log.level === 30 && | ||
| ( | ||
| log.msg.match('response received') || | ||
| log.msg.match('fetching from remote server') | ||
| ) | ||
| ) { | ||
| t.pass('request log message does not logged') | ||
| } | ||
| }) | ||
| instance.listen({ port: 0 }, (err) => { | ||
| t.error(err) | ||
| get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
| t.error(err) | ||
| t.equal(res.headers['content-type'], 'text/plain') | ||
| t.equal(res.headers['x-my-header'], 'hello!') | ||
| t.equal(res.statusCode, 205) | ||
| t.equal(data.toString(), 'hello world') | ||
| t.end() | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
| name: CI | ||
| 'on': | ||
| on: | ||
| push: | ||
| paths-ignore: | ||
| - docs/** | ||
| - 'docs/**' | ||
| - '*.md' | ||
| pull_request: | ||
| paths-ignore: | ||
| - docs/** | ||
| - 'docs/**' | ||
| - '*.md' | ||
| jobs: | ||
| test: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| node-version: | ||
| - 14 | ||
| - 16 | ||
| - 18 | ||
| os: | ||
| - macos-latest | ||
| - ubuntu-latest | ||
| - windows-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Use Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Install Dependencies | ||
| run: | | ||
| npm install --ignore-scripts | ||
| - name: Run Tests | ||
| run: | | ||
| npm run test:ci | ||
| - name: Coveralls Parallel | ||
| uses: coverallsapp/github-action@1.1.3 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| parallel: true | ||
| flag-name: run-${{ matrix.node-version }}-${{ matrix.os }} | ||
| coverage: | ||
| needs: test | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Coveralls Finished | ||
| uses: coverallsapp/github-action@1.1.3 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| parallel-finished: true | ||
| automerge: | ||
| needs: test | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| contents: write | ||
| steps: | ||
| - uses: fastify/github-action-merge-dependabot@v3.1.4 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 |
+1
-0
@@ -94,2 +94,3 @@ /// <reference types="node" /> | ||
| maxRetriesOn503?: number; | ||
| disableRequestLogging?: boolean; | ||
| } | ||
@@ -96,0 +97,0 @@ |
+7
-3
@@ -36,2 +36,3 @@ 'use strict' | ||
| }) | ||
| const disableRequestLogging = opts.disableRequestLogging || false | ||
@@ -124,3 +125,3 @@ fastify.decorateReply('from', function (source, opts) { | ||
| this.request.log.info({ source }, 'fetching from remote server') | ||
| !disableRequestLogging && this.request.log.info({ source }, 'fetching from remote server') | ||
@@ -150,3 +151,3 @@ const requestHeaders = rewriteRequestHeaders(req, headers) | ||
| } | ||
| this.request.log.info('response received') | ||
| !disableRequestLogging && this.request.log.info('response received') | ||
| if (sourceHttp2) { | ||
@@ -185,3 +186,6 @@ copyHeaders( | ||
| next() | ||
| }, '4.x') | ||
| }, { | ||
| fastify: '4.x', | ||
| name: '@fastify/reply-from' | ||
| }) | ||
@@ -188,0 +192,0 @@ function getQueryString (search, reqUrl, opts) { |
+18
-21
| { | ||
| "name": "@fastify/reply-from", | ||
| "version": "8.0.0", | ||
| "version": "8.1.0", | ||
| "description": "forward your HTTP request to another server, for fastify", | ||
@@ -29,36 +29,33 @@ "main": "index.js", | ||
| }, | ||
| "engines": { | ||
| "node": ">=12.18" | ||
| }, | ||
| "homepage": "https://github.com/fastify/fastify-reply-from#readme", | ||
| "devDependencies": { | ||
| "@fastify/formbody": "^7.0.0", | ||
| "@fastify/multipart": "^7.0.0", | ||
| "@sinonjs/fake-timers": "^9.0.0", | ||
| "@types/node": "^17.0.0", | ||
| "@types/tap": "^15.0.3", | ||
| "fastify": "^4.0.0-rc.2", | ||
| "@fastify/formbody": "^7.0.1", | ||
| "@fastify/multipart": "^7.1.0", | ||
| "@sinonjs/fake-timers": "^9.1.2", | ||
| "@types/node": "^18.0.0", | ||
| "@types/tap": "^15.0.7", | ||
| "fastify": "^4.0.2", | ||
| "form-data": "^4.0.0", | ||
| "got": "^11.8.2", | ||
| "h2url": "^0.2.0", | ||
| "msgpack5": "^6.0.0", | ||
| "nock": "^13.1.0", | ||
| "msgpack5": "^6.0.1", | ||
| "nock": "^13.2.6", | ||
| "pre-commit": "^1.2.2", | ||
| "proxyquire": "^2.1.3", | ||
| "simple-get": "^4.0.0", | ||
| "simple-get": "^4.0.1", | ||
| "snazzy": "^9.0.0", | ||
| "split2": "^4.0.0", | ||
| "split2": "^4.1.0", | ||
| "standard": "^17.0.0", | ||
| "tap": "^16.0.0", | ||
| "tsd": "^0.20.0", | ||
| "typescript": "^4.3.2" | ||
| "tap": "^16.2.0", | ||
| "tsd": "^0.21.0", | ||
| "typescript": "^4.7.3" | ||
| }, | ||
| "dependencies": { | ||
| "end-of-stream": "^1.4.4", | ||
| "fastify-plugin": "^3.0.0", | ||
| "fastify-plugin": "^3.0.1", | ||
| "http-errors": "^2.0.0", | ||
| "pump": "^3.0.0", | ||
| "semver": "^7.3.5", | ||
| "tiny-lru": "^8.0.1", | ||
| "undici": "^5.0.0" | ||
| "semver": "^7.3.7", | ||
| "tiny-lru": "^8.0.2", | ||
| "undici": "^5.5.1" | ||
| }, | ||
@@ -65,0 +62,0 @@ "tsd": { |
+13
-2
@@ -5,4 +5,2 @@ # @fastify/reply-from | ||
| [](https://www.npmjs.com/package/@fastify/reply-from) | ||
| [](https://snyk.io/test/github/fastify/fastify-reply-from) | ||
| [](https://coveralls.io/github/fastify/fastify-reply-from?branch=master) | ||
| [](https://standardjs.com/) | ||
@@ -179,2 +177,15 @@ | ||
| #### `disableRequestLogging` | ||
| By default package will issue log messages when a request is received. By setting this option to true, these log messages will be disabled. | ||
| Default for `disableRequestLogging` will be `false`. To disable the log messages set `disableRequestLogging` to `true`. | ||
| ```js | ||
| proxy.register(require('@fastify/reply-from'), { | ||
| base: 'http://localhost:3001/', | ||
| disableRequestLogging: true // request log messages will be disabled | ||
| }) | ||
| ``` | ||
| #### `cacheURLs` | ||
@@ -181,0 +192,0 @@ |
@@ -47,2 +47,3 @@ import replyFrom, { FastifyReplyFromOptions } from "../"; | ||
| maxRetriesOn503: 10, | ||
| disableRequestLogging: false, | ||
| }; | ||
@@ -49,0 +50,0 @@ tap.autoend(false); |
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
149943
2.22%89
1.14%4432
3.41%347
3.27%Updated
Updated
Updated
Updated