mirror of
https://github.com/JonasunderscoreJones/analytics.jonasjones.dev.git
synced 2025-10-22 17:09:18 +02:00
fixed analytics request
This commit is contained in:
parent
8a52ed518e
commit
53e9dd02fc
1 changed files with 14 additions and 10 deletions
24
src/index.js
24
src/index.js
|
@ -50,8 +50,12 @@ export default {
|
|||
|
||||
const record = { timestamp, domain, method, path, country };
|
||||
|
||||
// Store the new record in the database
|
||||
await this.storeRecordInDB(record, env);
|
||||
try {
|
||||
// Store the new record in the database
|
||||
await this.storeRecordInDB(record, env);
|
||||
} catch (error) {
|
||||
return new Response('Error storing record in DB', { status: 500 });
|
||||
}
|
||||
|
||||
return new Response('Recorded', { status: 200 });
|
||||
} catch (error) {
|
||||
|
@ -80,8 +84,12 @@ export default {
|
|||
|
||||
const record = { timestamp, domain, method, path, country };
|
||||
|
||||
// Store the new record in the database
|
||||
await this.storeRecordInDB(record, env);
|
||||
try {
|
||||
// Store the new record in the database
|
||||
await this.storeRecordInDB(record, env);
|
||||
} catch (error) {
|
||||
return new Response('Error storing record in DB', { status: 500 });
|
||||
}
|
||||
|
||||
const origin = request.headers.get('Origin');
|
||||
const isAllowedOrigin = ALLOWED_ORIGINS.includes(origin) || ALLOWED_ORIGINS.includes('localhost');
|
||||
|
@ -151,13 +159,9 @@ export default {
|
|||
|
||||
// Store the new record in the database
|
||||
async storeRecordInDB(record, env) {
|
||||
try {
|
||||
await env.DB.prepare('INSERT INTO requests (timestamp, domain, method, path, country) VALUES (?, ?, ?, ?, ?)')
|
||||
.bind(record.timestamp, record.domain, record.method, record.path, record.country)
|
||||
.run();
|
||||
} catch (error) {
|
||||
console.error('Error storing record in DB:', error);
|
||||
}
|
||||
.bind(record.timestamp, record.domain, record.method, record.path, record.country)
|
||||
.run();
|
||||
},
|
||||
|
||||
// Retrieve filtered records from the database
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue