fix(api): swift sdk has issues with double OpenPanel tags in user-agent, if so remove one

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-09 21:56:58 +01:00
parent af0f9717a8
commit 18874405b9
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import type {
FastifyReply,
FastifyRequest,
HookHandlerDoneFunction,
} from 'fastify';
export function fixHook(
request: FastifyRequest,
reply: FastifyReply,
done: HookHandlerDoneFunction,
) {
const ua = request.headers['user-agent'];
// Swift SDK issue: https://github.com/Openpanel-dev/swift-sdk/commit/d588fa761a36a33f3b78eb79d83bfd524e3c7144
if (ua) {
const regex = /OpenPanel\/(\d+\.\d+\.\d+)\sOpenPanel\/(\d+\.\d+\.\d+)/;
const match = ua.match(regex);
if (match) {
request.headers['user-agent'] = ua.replace(
regex,
`OpenPanel/${match[1]}`,
);
}
}
done();
}