diff --git a/lib/handlers/errors.js b/lib/handlers/errors.js index e9226ac9..72be10db 100644 --- a/lib/handlers/errors.js +++ b/lib/handlers/errors.js @@ -28,6 +28,12 @@ const handler = (err, req, res) => { message: err.message }) } + if (err.name && err.name === 'FastifyError') { + return res.status(err.statusCode).send({ + statusCode: err.statusCode, + message: err.message + }) + } if (err.name && err.name === 'UnauthorizedError') { return res.status(401).send({ statusCode: 401, diff --git a/package-lock.json b/package-lock.json index 06296e85..b9e17b5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "qryn", - "version": "3.0.11", + "version": "3.0.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "qryn", - "version": "3.0.11", + "version": "3.0.12", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { "@apla/clickhouse": "^1.6.4", "@cloki/clickhouse-sql": "1.2.10", + "@fastify/basic-auth": "^5.1.0", "@fastify/compress": "^6.5.0", "@fastify/cors": "^8.4.1", "@fastify/formbody": "^7.4.0", @@ -29,7 +30,6 @@ "date-fns": "^2.27.0", "fast-querystring": "^1.1.0", "fastify": "^4.24.3", - "fastify-basic-auth": "^2.3.0", "fastify-metrics": "^10.3.3", "fastify-plugin": "^4.5.1", "glob": "^7.1.2", @@ -955,6 +955,15 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, + "node_modules/@fastify/basic-auth": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@fastify/basic-auth/-/basic-auth-5.1.0.tgz", + "integrity": "sha512-oZYuI9EJQMdor1fZybb/sqV5zxbux2pSV7LK6Tj+Y/ZM1fuwK9jFYxNSur4tbTiJ+oFjDtbVvKaNBiSzqLaqdw==", + "dependencies": { + "@fastify/error": "^3.0.0", + "fastify-plugin": "^4.0.0" + } + }, "node_modules/@fastify/busboy": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz", @@ -5868,66 +5877,6 @@ "toad-cache": "^3.3.0" } }, - "node_modules/fastify-basic-auth": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/fastify-basic-auth/-/fastify-basic-auth-2.3.0.tgz", - "integrity": "sha512-+FG/jbHkcCSefdCX8gp+ZSUzpZgLGJUAnyF6J1gQlvAfVtAbnjGu0w9u68qXiTdQF37+qQSwZ5tC95cUcTeBbA==", - "deprecated": "Please use @fastify/basic-auth@3.0.0 instead", - "dependencies": { - "fastify-basic-auth-deprecated": "npm:fastify-basic-auth@2.2.0", - "process-warning": "^1.0.0" - } - }, - "node_modules/fastify-basic-auth-deprecated": { - "name": "fastify-basic-auth", - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/fastify-basic-auth/-/fastify-basic-auth-2.2.0.tgz", - "integrity": "sha512-xXeNhyhONlQNoWIzy9rhms0td6PFL1KCRqu0lkEpd54Ju4dHLbB/woPwtK0Vutuqy0sDav77If6UtdfDajx44Q==", - "dependencies": { - "basic-auth": "^2.0.1", - "fastify-plugin": "^3.0.0", - "http-errors": "^1.7.3" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/fastify-basic-auth-deprecated/node_modules/depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fastify-basic-auth-deprecated/node_modules/fastify-plugin": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz", - "integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==" - }, - "node_modules/fastify-basic-auth-deprecated/node_modules/http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", - "dependencies": { - "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.1" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fastify-basic-auth-deprecated/node_modules/statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/fastify-metrics": { "version": "10.3.3", "resolved": "https://registry.npmjs.org/fastify-metrics/-/fastify-metrics-10.3.3.tgz", @@ -14263,6 +14212,15 @@ } } }, + "@fastify/basic-auth": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@fastify/basic-auth/-/basic-auth-5.1.0.tgz", + "integrity": "sha512-oZYuI9EJQMdor1fZybb/sqV5zxbux2pSV7LK6Tj+Y/ZM1fuwK9jFYxNSur4tbTiJ+oFjDtbVvKaNBiSzqLaqdw==", + "requires": { + "@fastify/error": "^3.0.0", + "fastify-plugin": "^4.0.0" + } + }, "@fastify/busboy": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz", @@ -18114,54 +18072,6 @@ } } }, - "fastify-basic-auth": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/fastify-basic-auth/-/fastify-basic-auth-2.3.0.tgz", - "integrity": "sha512-+FG/jbHkcCSefdCX8gp+ZSUzpZgLGJUAnyF6J1gQlvAfVtAbnjGu0w9u68qXiTdQF37+qQSwZ5tC95cUcTeBbA==", - "requires": { - "fastify-basic-auth-deprecated": "npm:fastify-basic-auth@2.2.0", - "process-warning": "^1.0.0" - } - }, - "fastify-basic-auth-deprecated": { - "version": "npm:fastify-basic-auth@2.2.0", - "resolved": "https://registry.npmjs.org/fastify-basic-auth/-/fastify-basic-auth-2.2.0.tgz", - "integrity": "sha512-xXeNhyhONlQNoWIzy9rhms0td6PFL1KCRqu0lkEpd54Ju4dHLbB/woPwtK0Vutuqy0sDav77If6UtdfDajx44Q==", - "requires": { - "basic-auth": "^2.0.1", - "fastify-plugin": "^3.0.0", - "http-errors": "^1.7.3" - }, - "dependencies": { - "depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==" - }, - "fastify-plugin": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz", - "integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==" - }, - "http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", - "requires": { - "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.1" - } - }, - "statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" - } - } - }, "fastify-metrics": { "version": "10.3.3", "resolved": "https://registry.npmjs.org/fastify-metrics/-/fastify-metrics-10.3.3.tgz", diff --git a/package.json b/package.json index 7cec6361..a86713a9 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@fastify/static": "^6.12.0", "@fastify/websocket": "^8.2.0", "@fastify/url-data": "^5.4.0", + "@fastify/basic-auth": "^5.1.0", "@qxip/influx-line-protocol-parser": "^0.2.1", "@qxip/plugnplay": "^3.3.1", "@stricjs/router": "^5.0.6", @@ -49,7 +50,6 @@ "date-fns": "^2.27.0", "fast-querystring": "^1.1.0", "fastify": "^4.24.3", - "fastify-basic-auth": "^2.3.0", "fastify-metrics": "^10.3.3", "fastify-plugin": "^4.5.1", "glob": "^7.1.2", diff --git a/qryn_node.js b/qryn_node.js index ab6f0dc8..aa3cccad 100755 --- a/qryn_node.js +++ b/qryn_node.js @@ -182,7 +182,7 @@ let fastify = require('fastify')({ const validate = checkAuth.bind(this) - fastify.register(require('fastify-basic-auth'), { + fastify.register(require('@fastify/basic-auth'), { validate, authenticate: true })