feat: feed stats
This commit is contained in:
parent
9b702520e2
commit
2cd3100200
3 changed files with 43 additions and 3 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "22.2.1.",
|
"version": "22.3.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "22.2.1.",
|
"version": "22.3.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cdransf/api-text": "^1.5.0",
|
"@cdransf/api-text": "^1.5.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "22.2.1.",
|
"version": "22.3.0",
|
||||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -5,6 +5,46 @@ addEventListener('fetch', event => {
|
||||||
async function handleRequest(request) {
|
async function handleRequest(request) {
|
||||||
const url = new URL(request.url)
|
const url = new URL(request.url)
|
||||||
|
|
||||||
|
if (url.pathname.startsWith('/feeds/')) {
|
||||||
|
const response = await fetch(request)
|
||||||
|
const rssFeed = await response.text()
|
||||||
|
const UMAMI_API_KEY = env.UMAMI_API_KEY
|
||||||
|
const feedName = url.pathname.split('/feeds/')[1] || 'unknown'
|
||||||
|
const userAgent = request.headers.get('User-Agent') || 'unknown'
|
||||||
|
const analyticsPayload = {
|
||||||
|
type: 'event',
|
||||||
|
payload: {
|
||||||
|
website: UMAMI_API_KEY,
|
||||||
|
hostname: url.hostname,
|
||||||
|
url: url.pathname,
|
||||||
|
referrer: request.headers.get('Referer') || '',
|
||||||
|
language: request.headers.get('Accept-Language') || '',
|
||||||
|
title: 'RSS Feed Access',
|
||||||
|
name: 'rss_feed_view',
|
||||||
|
data: {
|
||||||
|
feed: feedName,
|
||||||
|
userAgent: userAgent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetch('https://dashboard.coryd.dev/api/collect', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${UMAMI_API_KEY}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify(analyticsPayload)
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(rssFeed, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/rss+xml'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (url.pathname === '/js/script.js') {
|
if (url.pathname === '/js/script.js') {
|
||||||
const targetUrl = 'https://dashboard.coryd.dev/script.js'
|
const targetUrl = 'https://dashboard.coryd.dev/script.js'
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
|
|
Reference in a new issue