mirror of
https://github.com/JonasunderscoreJones/rick-roll-tracker.git
synced 2025-10-24 12:09:18 +02:00
added rick roll tracker
This commit is contained in:
parent
f431b8a5e8
commit
8fe3037bbb
1 changed files with 32 additions and 11 deletions
43
src/index.js
43
src/index.js
|
|
@ -1,15 +1,36 @@
|
|||
/**
|
||||
* Welcome to Cloudflare Workers! This is your first worker.
|
||||
*
|
||||
* - Run `npm run dev` in your terminal to start a development server
|
||||
* - Open a browser tab at http://localhost:8787/ to see your worker in action
|
||||
* - Run `npm run deploy` to publish your worker
|
||||
*
|
||||
* Learn more at https://developers.cloudflare.com/workers/
|
||||
*/
|
||||
|
||||
export default {
|
||||
async fetch(request, env, ctx) {
|
||||
return new Response('Hello World!');
|
||||
await recordRequest(request, env);
|
||||
return Response.redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 302);
|
||||
},
|
||||
};
|
||||
|
||||
async function recordRequest(request, env) {
|
||||
|
||||
const url = new URL(request.url);
|
||||
|
||||
const analyticsData = {
|
||||
timestamp: Date.now(),
|
||||
domain: url.hostname,
|
||||
method: request.method,
|
||||
path: url.pathname,
|
||||
country: request.cf.country,
|
||||
}
|
||||
console.log('Recording request:', analyticsData);
|
||||
const ANALYTICS_URL = 'https://analytics.jonasjones.dev/requests/record';
|
||||
|
||||
const response = await fetch(ANALYTICS_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': env.VITE_ANALYTICS_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(analyticsData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log('Request recorded successfully');
|
||||
} else {
|
||||
console.error('Failed to record request:', response.status, await response.text());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue