Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@fastify/reply-from

Package Overview
Dependencies
Maintainers
19
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/reply-from - npm Package Compare versions

Comparing version
8.0.0
to
8.1.0
+159
test/disable-request-logging.js
'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()
})
})
})
})
+6
-51
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

@@ -94,2 +94,3 @@ /// <reference types="node" />

maxRetriesOn503?: number;
disableRequestLogging?: boolean;
}

@@ -96,0 +97,0 @@

@@ -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) {

{
"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": {

@@ -5,4 +5,2 @@ # @fastify/reply-from

[![NPM version](https://img.shields.io/npm/v/@fastify/reply-from.svg?style=flat)](https://www.npmjs.com/package/@fastify/reply-from)
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-reply-from/badge.svg)](https://snyk.io/test/github/fastify/fastify-reply-from)
[![Coverage Status](https://coveralls.io/repos/github/fastify/fastify-reply-from/badge.svg?branch=master)](https://coveralls.io/github/fastify/fastify-reply-from?branch=master)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](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);