Files
klz-cables.com/lib/services/create-services.server.ts
Marc Mintel f2dd76a7a6
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m30s
build
2026-01-26 02:30:19 +01:00

40 lines
1.4 KiB
TypeScript

import { AppServices } from './app-services';
import { NoopAnalyticsService } from './analytics/noop-analytics-service';
import { UmamiAnalyticsService } from './analytics/umami-analytics-service';
import { MemoryCacheService } from './cache/memory-cache-service';
import { RedisCacheService } from './cache/redis-cache-service';
import { GlitchtipErrorReportingService } from './errors/glitchtip-error-reporting-service';
import { NoopErrorReportingService } from './errors/noop-error-reporting-service';
import { PinoLoggerService } from './logging/pino-logger-service';
let singleton: AppServices | undefined;
export function getServerAppServices(): AppServices {
if (singleton) return singleton;
const umamiEnabled = Boolean(process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID);
const sentryEnabled = Boolean(process.env.SENTRY_DSN);
const analytics = umamiEnabled
? new UmamiAnalyticsService({ enabled: true })
: new NoopAnalyticsService();
const errors = sentryEnabled
? new GlitchtipErrorReportingService({ enabled: true })
: new NoopErrorReportingService();
const redisUrl = process.env.REDIS_URL;
const cache = redisUrl
? new RedisCacheService({
url: redisUrl,
keyPrefix: process.env.REDIS_KEY_PREFIX ?? 'klz:',
})
: new MemoryCacheService();
const logger = new PinoLoggerService('server');
singleton = new AppServices(analytics, errors, cache, logger);
return singleton;
}