diff options
author | 2024-05-03 17:40:53 +0200 | |
---|---|---|
committer | 2024-05-03 17:40:53 +0200 | |
commit | a37d76a42ac00697be3acd575f3f7163129ea75c (patch) | |
tree | 99c2c542e07eb49643cb682cecc31250dfd8bd9e /packages/integrations/web-vitals/src/endpoint.ts | |
parent | befbda7fa3d712388789a5a9be1e0597834f86db (diff) | |
download | astro-a37d76a42ac00697be3acd575f3f7163129ea75c.tar.gz astro-a37d76a42ac00697be3acd575f3f7163129ea75c.tar.zst astro-a37d76a42ac00697be3acd575f3f7163129ea75c.zip |
Add web-vitals integration (#10883)
Diffstat (limited to 'packages/integrations/web-vitals/src/endpoint.ts')
-rw-r--r-- | packages/integrations/web-vitals/src/endpoint.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/integrations/web-vitals/src/endpoint.ts b/packages/integrations/web-vitals/src/endpoint.ts new file mode 100644 index 000000000..10dea1ca8 --- /dev/null +++ b/packages/integrations/web-vitals/src/endpoint.ts @@ -0,0 +1,23 @@ +import { db, sql } from 'astro:db'; +import type { APIRoute } from 'astro'; +import { AstrojsWebVitals_Metric } from './db-config.js'; +import { ServerMetricSchema } from './schemas.js'; + +export const prerender = false; + +export const ALL: APIRoute = async ({ request }) => { + try { + const rawBody = await request.json(); + const body = ServerMetricSchema.array().parse(rawBody); + await db + .insert(AstrojsWebVitals_Metric) + .values(body) + .onConflictDoUpdate({ + target: AstrojsWebVitals_Metric.id, + set: { value: sql`excluded.value` }, + }); + } catch (error) { + console.error(error); + } + return new Response(); +}; |