ADD CROSS DOMAIN SUPPORT

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-26 22:35:29 +02:00
parent a0c8199474
commit 41143ca5f8
26 changed files with 514 additions and 126 deletions

View File

@@ -17,16 +17,15 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
reply
) => {
try {
const projectId = await validateSdkRequest(req.headers).catch(
(error) => {
logger.error(error, 'Failed to validate sdk request');
return null;
}
);
if (!projectId) {
const client = await validateSdkRequest(req.headers).catch((error) => {
logger.error(error, 'Failed to validate sdk request');
return null;
});
if (!client?.projectId) {
return reply.status(401).send();
}
req.projectId = projectId;
req.projectId = client.projectId;
req.client = client;
const bot = req.headers['user-agent']
? isBot(req.headers['user-agent'])
@@ -37,7 +36,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
req.body?.properties?.path) as string | undefined;
await createBotEvent({
...bot,
projectId,
projectId: client.projectId,
path: path ?? '',
createdAt: new Date(req.body?.timestamp),
});