chore: improve cors

This commit is contained in:
DarkSky
2026-02-24 00:51:08 +08:00
parent 744c78abbb
commit e617740974
2 changed files with 44 additions and 17 deletions
@@ -6,6 +6,8 @@ import { TelemetryDeduper } from './deduper';
import { Ga4Client } from './ga4-client';
import { TelemetryAck, TelemetryBatch } from './types';
const TELEMETRY_ROUTE_PATTERN = /\/api\/telemetry(?:\/|$)/;
@Injectable()
export class TelemetryService {
private readonly logger = new Logger(TelemetryService.name);
@@ -71,6 +73,13 @@ export class TelemetryService {
return false;
}
getAllowedOrigins(routePath?: string): string[] {
if (routePath && TELEMETRY_ROUTE_PATTERN.test(routePath)) {
return [...this.allowedOrigins];
}
return [];
}
async collectBatch(batch: TelemetryBatch): Promise<TelemetryAck> {
if (!batch || batch.schemaVersion !== 1 || !Array.isArray(batch.events)) {
return {