diff --git a/.gitignore b/.gitignore index 8395e0d..5d01302 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ Cargo.lock /public/ -/node_modules/ \ No newline at end of file +/node_modules/ + +.dev.vars \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 38ff267..0000000 --- a/package-lock.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "name": "ewpratten.com", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "dependencies": { - "bootstrap": "^5.2.3", - "github-markdown-css": "^5.1.0", - "line-awesome": "^1.3.0" - } - }, - "node_modules/@popperjs/core": { - "version": "2.11.6", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", - "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", - "peer": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/popperjs" - } - }, - "node_modules/bootstrap": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.3.tgz", - "integrity": "sha512-cEKPM+fwb3cT8NzQZYEu4HilJ3anCrWqh3CHAok1p9jXqMPsPTBhU25fBckEJHJ/p+tTxTFTsFQGM+gaHpi3QQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/twbs" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/bootstrap" - } - ], - "peerDependencies": { - "@popperjs/core": "^2.11.6" - } - }, - "node_modules/github-markdown-css": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/github-markdown-css/-/github-markdown-css-5.1.0.tgz", - "integrity": "sha512-QLtORwHHtUHhPMHu7i4GKfP6Vx5CWZn+NKQXe+cBhslY1HEt0CTEkP4d/vSROKV0iIJSpl4UtlQ16AD8C6lMug==", - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/line-awesome": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/line-awesome/-/line-awesome-1.3.0.tgz", - "integrity": "sha512-Y0YHksL37ixDsHz+ihCwOtF5jwJgCDxQ3q+zOVgaSW8VugHGTsZZXMacPYZB1/JULBi6BAuTCTek+4ZY/UIwcw==" - } - }, - "dependencies": { - "@popperjs/core": { - "version": "2.11.6", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", - "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", - "peer": true - }, - "bootstrap": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.3.tgz", - "integrity": "sha512-cEKPM+fwb3cT8NzQZYEu4HilJ3anCrWqh3CHAok1p9jXqMPsPTBhU25fBckEJHJ/p+tTxTFTsFQGM+gaHpi3QQ==", - "requires": {} - }, - "github-markdown-css": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/github-markdown-css/-/github-markdown-css-5.1.0.tgz", - "integrity": "sha512-QLtORwHHtUHhPMHu7i4GKfP6Vx5CWZn+NKQXe+cBhslY1HEt0CTEkP4d/vSROKV0iIJSpl4UtlQ16AD8C6lMug==" - }, - "line-awesome": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/line-awesome/-/line-awesome-1.3.0.tgz", - "integrity": "sha512-Y0YHksL37ixDsHz+ihCwOtF5jwJgCDxQ3q+zOVgaSW8VugHGTsZZXMacPYZB1/JULBi6BAuTCTek+4ZY/UIwcw==" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 6a589d7..0000000 --- a/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "bootstrap": "^5.2.3", - "github-markdown-css": "^5.1.0", - "line-awesome": "^1.3.0" - } -} diff --git a/static/functions/_middleware.js b/static/functions/_middleware.js index fb2aba9..815b471 100644 --- a/static/functions/_middleware.js +++ b/static/functions/_middleware.js @@ -1,5 +1,14 @@ async function goat_counter_analytics(context) { + + // We require some env vars to be set. If they are not, fail the request + if (!context.env.GOAT_COUNTER_API_KEY) { + return new Response('$GOAT_COUNTER_API_KEY is not set', { status: 500, headers: { 'Content-Type': 'text/plain' } }); + } + if (!context.env.GOAT_COUNTER_SITE_CODE) { + return new Response('$GOAT_COUNTER_SITE_CODE is not set', { status: 500, headers: { 'Content-Type': 'text/plain' } }); + } + // Parse the request URL let url = new URL(context.request.url); @@ -17,13 +26,16 @@ async function goat_counter_analytics(context) { ] }; + // Count the goat + // await fetch() + // Execute the rest of the request chain let response = await context.next(); // For debugging, allow the requester to expose the body through a response header if (url.searchParams.get('goat-counter-debug') == 'true') { response.headers.set('X-GoatCounter-Payload', JSON.stringify(payload)); - response.headers.set('X-GoatCounter-Api-Token', context.env.GOAT_COUNTER_API_TOKEN); + response.headers.set('X-GoatCounter-Api-Token', context.env.GOAT_COUNTER_API_KEY); } // Return the response