Testing self-hosting

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-01 09:27:28 +02:00
parent 11d262cc2a
commit 7572d27f77

View File

@@ -1,3 +1,4 @@
import { logger } from '@/utils/logger';
import { getClientIp, parseIp } from '@/utils/parseIp';
import type { FastifyReply, FastifyRequest } from 'fastify';
@@ -12,6 +13,56 @@ export async function postEvent(
}>,
reply: FastifyReply
) {
if (process.env.TEST_SELF_HOSTING) {
try {
logger.info(
{
['X-Forwarded-For']: request.headers['X-Forwarded-For'] as string,
['x-real-ip']: request.headers['x-real-ip'] as string,
origin: request.headers.origin!,
'user-agent': request.headers['user-agent']!,
'Content-Type': 'application/json',
'openpanel-client-id': request.headers[
'openpanel-client-id'
] as string,
'openpanel-client-secret': request.headers[
'openpanel-client-secret'
] as string,
'mixan-client-id': request.headers['mixan-client-id'] as string,
'mixan-client-secret': request.headers[
'mixan-client-secret'
] as string,
},
'Sending event to op.coderax.se'
);
// Test batching on a different service
await fetch('https://op.coderax.se/api/event', {
headers: {
['X-Forwarded-For']: request.headers['X-Forwarded-For'] as string,
['x-real-ip']: request.headers['x-real-ip'] as string,
origin: request.headers.origin!,
'user-agent': request.headers['user-agent']!,
'Content-Type': 'application/json',
'openpanel-client-id': request.headers[
'openpanel-client-id'
] as string,
'openpanel-client-secret': request.headers[
'openpanel-client-secret'
] as string,
'mixan-client-id': request.headers['mixan-client-id'] as string,
'mixan-client-secret': request.headers[
'mixan-client-secret'
] as string,
},
method: 'POST',
body: JSON.stringify(request.body),
})
.then((res) => res.json())
.catch((res) => res);
} catch (e) {
logger.error(e);
}
}
const ip = getClientIp(request)!;
const ua = request.headers['user-agent']!;
const origin = request.headers.origin!;