Skip to content

Open-source status page, incident response and uptime monitoring

2.4 KB
Raw Blame
import { createConnectRouter } from "@connectrpc/connect";
import { HealthService } from "@openstatus/proto/health/v1";
import { IncidentService } from "@openstatus/proto/incident/v1";
import { MaintenanceService } from "@openstatus/proto/maintenance/v1";
import { MonitorService } from "@openstatus/proto/monitor/v1";
import { NotificationService } from "@openstatus/proto/notification/v1";
import { PrivateLocationService } from "@openstatus/proto/private_location/v1";
import { StatusPageService } from "@openstatus/proto/status_page/v1";
import { StatusReportService } from "@openstatus/proto/status_report/v1";

import { healthServiceImpl } from "./handlers/health";
import { incidentServiceImpl } from "./handlers/incident";
import { maintenanceServiceImpl } from "./handlers/maintenance";
import { monitorServiceImpl } from "./handlers/monitor";
import { notificationServiceImpl } from "./handlers/notification";
import { privateLocationServiceImpl } from "./handlers/private-location";
import { statusPageServiceImpl } from "./handlers/status-page";
import { statusReportServiceImpl } from "./handlers/status-report";
import {
  authInterceptor,
  errorInterceptor,
  loggingInterceptor,
  trackingInterceptor,
  validationInterceptor,
} from "./interceptors";

/**
 * Create ConnectRPC router with services.
 * Interceptors are applied in order (outermost to innermost):
 * 1. errorInterceptor - Catches all errors and maps to ConnectError
 * 2. loggingInterceptor - Logs requests/responses with duration
 * 3. authInterceptor - Validates API key and sets workspace context
 * 4. validationInterceptor - Validates request messages using protovalidate
 * 5. trackingInterceptor - Fires OpenPanel `api_request` for authenticated, validated calls + domain events on success
 */
export const routes = createConnectRouter({
  interceptors: [
    errorInterceptor(),
    loggingInterceptor(),
    authInterceptor(),
    validationInterceptor(),
    trackingInterceptor(),
  ],
})
  .service(MonitorService, monitorServiceImpl)
  .service(HealthService, healthServiceImpl)
  .service(StatusReportService, statusReportServiceImpl)
  .service(StatusPageService, statusPageServiceImpl)
  .service(MaintenanceService, maintenanceServiceImpl)
  .service(NotificationService, notificationServiceImpl)
  .service(PrivateLocationService, privateLocationServiceImpl)
  .service(IncidentService, incidentServiceImpl);