From b6a41fe04a52d05b5a70b812e4eb235f88cda3a2 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 16 Oct 2024 23:19:20 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=83=D1=87=D0=B8=D1=82=D1=8B=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B0=D0=BD=D0=B0=D0=BB=D0=B8=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/main.js b/server/main.js index 5cd666f..dfea259 100644 --- a/server/main.js +++ b/server/main.js @@ -34,7 +34,7 @@ fastify.register(configurationRoutes); fastify.register(HomeRoute); fastify.addHook('onResponse', async (request, reply) => { - if (!config['analytics']['work']) return; + if (!config?.['analytics']['work']) return; const userAgent = request.headers['user-agent']; const parser = new UAParser(userAgent); @@ -43,22 +43,23 @@ fastify.addHook('onResponse', async (request, reply) => { const event = { domain: config['analytics']['plausible_domain'], - name: request.routerPath || '404 - Not Found', + name: request.routeOptions.url ? request.routeOptions.url : '404 - Not Found', url: request.raw.url, props: { method: request.method, statusCode: reply.statusCode, browser: `${browser.name} ${browser.version}`, os: `${os.name} ${os.version}`, - source: request.headers['referer'] || 'direct', + source: request.headers['referer'] ? request.headers['referer'] : 'direct', }, }; try { - await axios.post(config['analytics']['plausible_api'], event, { - headers: { - Authorization: `Bearer ${config['analytics']['plausible_token']}`, - 'Content-Type': 'application/json', + await axios.post(config['analytics']['plausible_api'], event, { + headers: { + Authorization: `Bearer ${config['analytics']['plausible_token']}`, + 'Content-Type': 'application/json', + 'User-Agent': userAgent, }, }); } catch (error) {