Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmarks/origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
Expand Down
8 changes: 4 additions & 4 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async function fastifyHttpProxy (fastify, opts) {
return headers
}

function bodyParser (req, payload, done) {
function bodyParser (_req, payload, done) {
done(null, payload)
}

Expand Down
44 changes: 22 additions & 22 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand All @@ -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'
})
Expand Down Expand Up @@ -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}`
}
}
Expand Down Expand Up @@ -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}`
}
}
Expand Down Expand Up @@ -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}`
}
}
Expand Down Expand Up @@ -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}`
}
}
Expand All @@ -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()
}
Expand All @@ -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()
}
})
Expand Down Expand Up @@ -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: '/',
Expand Down Expand Up @@ -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'
})

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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']
}
})
Expand Down Expand Up @@ -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 })
Expand Down
6 changes: 3 additions & 3 deletions test/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions test/ws-prefix-rewrite-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ async function processRequest (t, frontendURL, path, expected) {
t.comment('websocket closed')
wsResult = 'error'
}
} catch (e) {
} catch {
wsResult = 'error'
ws.terminate()
}

try {
const result = await got(url)
gotResult = result.body
} catch (e) {
} catch {
gotResult = 'error'
}

Expand All @@ -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()
})
}
Expand Down
6 changes: 3 additions & 3 deletions test/ws-prefix-rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ async function processRequest (t, frontendURL, path, expected) {
t.comment('websocket closed')
wsResult = 'error'
}
} catch (e) {
} catch {
wsResult = 'error'
ws.terminate()
}

try {
const result = await got(url)
gotResult = result.body
} catch (e) {
} catch {
gotResult = 'error'
}

Expand All @@ -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()
})
}
Expand Down
Loading