-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write web vitals to DynamoDB table
- Loading branch information
Showing
8 changed files
with
1,072 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
import awsLite from "@aws-lite/client" | ||
import awsDynamoDB from "@aws-lite/dynamodb" | ||
import type { ActionFunctionArgs } from "@remix-run/node" | ||
import { Resource } from "sst" | ||
|
||
import type { AnalyticsData } from "~/components/hooks/webVitals" | ||
|
||
interface DatabaseAnalyticsData extends AnalyticsData { | ||
id: string | ||
createdAt: string | ||
} | ||
|
||
export async function action({ request }: ActionFunctionArgs) { | ||
const data = (await request.json()) as Record<string, string> | ||
const aws = await awsLite({ | ||
region: "eu-central-1", | ||
plugins: [awsDynamoDB] | ||
}) | ||
|
||
const data = (await request.json()) as AnalyticsData | ||
|
||
const entry: DatabaseAnalyticsData = { ...data, id: data.metric.id, createdAt: new Date().toISOString() } | ||
|
||
try { | ||
|
||
console.log(">>>", data) | ||
// eslint-disable-next-line new-cap | ||
await aws.DynamoDB.PutItem({ | ||
TableName: Resource.WebVitals.name, | ||
Item: entry | ||
}) | ||
} catch (error) { | ||
return new Response(`Error saving data: ${error as string}`, { status: 500 }) | ||
} | ||
|
||
return new Response("", { status: 204 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@aws-lite/dynamodb'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.