diff --git a/benchmarks/origin.js b/benchmarks/origin.js index 2151727..b2bd70f 100644 --- a/benchmarks/origin.js +++ b/benchmarks/origin.js @@ -6,15 +6,15 @@ async function startOrigin () { const origin = Fastify({ http2: !!process.env.HTTP2 }) - origin.get('/', async (request, reply) => { + origin.get('/', async () => { return 'this is root' }) - origin.get('/a', async (request, reply) => { + origin.get('/a', async () => { return 'this is a' }) - origin.post('/this-has-data', async (request, reply) => { + origin.post('/this-has-data', async (request) => { if (request.body.hello === 'world') { return { something: 'posted' } } diff --git a/examples/example.js b/examples/example.js index 9236b50..bc26612 100644 --- a/examples/example.js +++ b/examples/example.js @@ -6,19 +6,19 @@ const proxy = require('..') async function startOrigin () { const origin = Fastify() - origin.get('/', async (request, reply) => { + origin.get('/', async () => { return 'this is root' }) - origin.get('/redirect', async (request, reply) => { + origin.get('/redirect', async (_request, reply) => { return reply.redirect(302, 'https://fastify.dev') }) - origin.get('/a', async (request, reply) => { + origin.get('/a', async () => { return 'this is a' }) - origin.post('/this-has-data', async (request, reply) => { + origin.post('/this-has-data', async (request) => { if (request.body.hello === 'world') { return { something: 'posted' } } diff --git a/index.js b/index.js index 41890a0..d355387 100644 --- a/index.js +++ b/index.js @@ -266,7 +266,7 @@ async function fastifyHttpProxy (fastify, opts) { return headers } - function bodyParser (req, payload, done) { + function bodyParser (_req, payload, done) { done(null, payload) } diff --git a/test/test.js b/test/test.js index 03744c6..6b8a548 100644 --- a/test/test.js +++ b/test/test.js @@ -10,15 +10,15 @@ const qs = require('fast-querystring') async function run () { const origin = Fastify() - origin.get('/', async (request, reply) => { + origin.get('/', async () => { return 'this is root' }) - origin.get('/a', async (request, reply) => { + origin.get('/a', async () => { return 'this is a' }) - origin.get('/redirect', async (request, reply) => { + origin.get('/redirect', async (_request, reply) => { return reply.redirect('https://fastify.dev', 302) }) @@ -30,24 +30,24 @@ async function run () { throw new Error('kaboom') }) - origin.post('/redirect-to-relative-url', async (request, reply) => { + origin.post('/redirect-to-relative-url', async (_request, reply) => { reply.header('location', '/relative-url') return { status: 'ok' } }) - origin.get('/api2/a', async (request, reply) => { + origin.get('/api2/a', async () => { return 'this is /api2/a' }) - origin.get('/variable-api/:id/endpoint', async (request, reply) => { + origin.get('/variable-api/:id/endpoint', async (request) => { return `this is "variable-api" endpoint with id ${request.params.id}` }) - origin.get('/variable-api/:id/endpoint-with-query', async (request, reply) => { + origin.get('/variable-api/:id/endpoint-with-query', async (request) => { return `this is "variable-api" endpoint with id ${request.params.id} and query params ${JSON.stringify(request.query)}` }) - origin.get('/timeout', async (request, reply) => { + origin.get('/timeout', async () => { await new Promise((resolve) => setTimeout(resolve, 600)) return 'this is never received' }) @@ -84,7 +84,7 @@ async function run () { t.fail('should never be called') }, replyOptions: { - getUpstream: function (original, base) { + getUpstream: function () { return `http://localhost:${origin.server.address().port}` } } @@ -130,7 +130,7 @@ async function run () { server.register(proxy, { upstream: '', replyOptions: { - getUpstream: function (original, base) { + getUpstream: function () { return `http://localhost:${origin.server.address().port}` } } @@ -195,7 +195,7 @@ async function run () { upstream: '', prefix: '/my-prefix', replyOptions: { - getUpstream: function (original, base) { + getUpstream: function () { return `http://localhost:${origin.server.address().port}` } } @@ -301,7 +301,7 @@ async function run () { server.register(proxy, { upstream: '', replyOptions: { - getUpstream: function (original, base) { + getUpstream: function () { return `http://localhost:${origin.server.address().port}` } } @@ -326,7 +326,7 @@ async function run () { server.register(proxy, { upstream: `http://localhost:${origin.server.address().port}`, proxyPayloads: false, - preHandler (request, reply, next) { + preHandler (request, _reply, next) { t.same(request.body, { hello: 'world' }) next() } @@ -349,7 +349,7 @@ async function run () { const server = Fastify() server.register(proxy, { upstream: `http://localhost:${origin.server.address().port}`, - async preHandler (request, reply) { + async preHandler () { throw new Unauthorized() } }) @@ -381,7 +381,7 @@ async function run () { server.register(proxy, { upstream: `http://localhost:${origin.server.address().port}`, config: { foo: 'bar' }, - async preHandler (request, reply) { + async preHandler (request) { t.same(request.routeOptions.config, { foo: 'bar', url: '/', @@ -415,7 +415,7 @@ async function run () { test('multiple prefixes with multiple plugins', async t => { const origin2 = Fastify() - origin2.get('/', async (request, reply) => { + origin2.get('/', async () => { return 'this is root for origin2' }) @@ -666,11 +666,11 @@ async function run () { upstream: `http://localhost:${origin.server.address().port}`, prefix: '/api', replyOptions: { - onResponse (request, reply, { stream }) { + onResponse (_request, reply, { stream }) { return reply.send( stream.pipe( new Transform({ - transform: function (chunk, enc, cb) { + transform: function (chunk, _enc, cb) { this.push(chunk.toString().toUpperCase()) cb() } @@ -788,8 +788,8 @@ async function run () { empty: () => { headerValues = {} } } }, - validate (value) { return true }, - deriveConstraint: (req, ctx) => { + validate () { return true }, + deriveConstraint: (req) => { return req.headers['test-header'] } }) @@ -867,10 +867,10 @@ async function run () { test('prefixed proxy with query search', async t => { const appServer = Fastify() - appServer.get('/second-service', async (request, reply) => { + appServer.get('/second-service', async (request) => { return `Hello World - lang = ${request.query.lang}` }) - appServer.get('/second-service/foo', async (request, reply) => { + appServer.get('/second-service/foo', async (request) => { return `Hello World (foo) - lang = ${request.query.lang}` }) const address = await appServer.listen({ port: 0 }) diff --git a/test/websocket.js b/test/websocket.js index 0590b20..b7530d3 100644 --- a/test/websocket.js +++ b/test/websocket.js @@ -284,7 +284,7 @@ test('websocket proxy trigger hooks', async (t) => { await promisify(origin.listen.bind(origin))({ port: 0, host: '127.0.0.1' }) const server = Fastify() - server.addHook('onRequest', (request, reply, done) => { + server.addHook('onRequest', (_request, _reply, done) => { t.pass('onRequest') done() }) @@ -347,7 +347,7 @@ test('websocket proxy with rewriteRequestHeaders', async (t) => { upstream: `ws://127.0.0.1:${origin.address().port}`, websocket: true, wsClientOptions: { - rewriteRequestHeaders: (headers, request) => { + rewriteRequestHeaders: (headers) => { return { ...headers, myauth: 'myauth' @@ -461,7 +461,7 @@ test('Should gracefully close when clients attempt to connect after calling clos server.server.close = function (cb) { const ws = new WebSocket('ws://127.0.0.1:' + server.server.address().port) - p = once(ws, 'unexpected-response').then(([req, res]) => { + p = once(ws, 'unexpected-response').then(([_req, res]) => { t.equal(res.statusCode, 503) oldClose.call(this, cb) }) diff --git a/test/ws-prefix-rewrite-core.js b/test/ws-prefix-rewrite-core.js index 77c7b4c..a1590ef 100644 --- a/test/ws-prefix-rewrite-core.js +++ b/test/ws-prefix-rewrite-core.js @@ -51,7 +51,7 @@ async function processRequest (t, frontendURL, path, expected) { t.comment('websocket closed') wsResult = 'error' } - } catch (e) { + } catch { wsResult = 'error' ws.terminate() } @@ -59,7 +59,7 @@ async function processRequest (t, frontendURL, path, expected) { try { const result = await got(url) gotResult = result.body - } catch (e) { + } catch { gotResult = 'error' } @@ -79,7 +79,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions }, wsHandler: (socket, req) => { socket.send(req.url) - socket.once('message', chunk => { + socket.once('message', () => { socket.close() }) } diff --git a/test/ws-prefix-rewrite.js b/test/ws-prefix-rewrite.js index ca74a71..8b12769 100644 --- a/test/ws-prefix-rewrite.js +++ b/test/ws-prefix-rewrite.js @@ -49,7 +49,7 @@ async function processRequest (t, frontendURL, path, expected) { t.comment('websocket closed') wsResult = 'error' } - } catch (e) { + } catch { wsResult = 'error' ws.terminate() } @@ -57,7 +57,7 @@ async function processRequest (t, frontendURL, path, expected) { try { const result = await got(url) gotResult = result.body - } catch (e) { + } catch { gotResult = 'error' } @@ -77,7 +77,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions }, wsHandler: (socket, req) => { socket.send(req.url) - socket.once('message', chunk => { + socket.once('message', () => { socket.close() }) }