From e591a00888a5bd51f86cc457b1099ea9cf18065a Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Fri, 2 Aug 2024 08:47:41 -0700 Subject: [PATCH] fix: analytics worker --- package-lock.json | 18 +++++++++--------- package.json | 2 +- workers/analytics/index.js | 13 +++++++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 254f8b9a..26c4eb94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "21.1.4", + "version": "21.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "21.1.4", + "version": "21.1.5", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.4.0", @@ -582,13 +582,13 @@ "peer": true }, "node_modules/@types/node": { - "version": "22.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.2.tgz", - "integrity": "sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", + "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~6.11.1" + "undici-types": "~6.13.0" } }, "node_modules/@types/phoenix": { @@ -3667,9 +3667,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index c80f3432..f46dec7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "21.1.4", + "version": "21.1.5", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "scripts": { diff --git a/workers/analytics/index.js b/workers/analytics/index.js index eebb14c1..f3b2b04b 100644 --- a/workers/analytics/index.js +++ b/workers/analytics/index.js @@ -1,7 +1,7 @@ const scriptName = '/js/script.js' const endpoint = '/api/event' -addEventListener('fetch', event => { +addEventListener("fetch", (event) => { event.passThroughOnException() event.respondWith(handleRequest(event)) }) @@ -10,8 +10,11 @@ async function handleRequest(event) { const url = new URL(event.request.url) const pathname = url.pathname - if (pathname === scriptName) getScript(event) - if (pathname === endpoint) return postData(event) + if (pathname === scriptName) { + return getScript(event) + } else if (pathname === endpoint) { + return postData(event) + } return new Response(null, { status: 404 }) } @@ -20,10 +23,12 @@ async function getScript(event) { let response = await cache.match(event.request) if (!response) { - const scriptUrl = 'https://plausible.io/js/plausible.outbound-links.tagged-events.js' + const scriptUrl = + 'https://plausible.io/js/plausible.outbound-links.tagged-events.js' response = await fetch(scriptUrl) if (response.ok) event.waitUntil(cache.put(event.request, response.clone())) } + return response }