Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

1.0 KB
Raw Blame
/*
 * Copyright 2025 Daytona Platforms Inc.
 * Modified by BoxLite AI, 2025-2026
 * SPDX-License-Identifier: AGPL-3.0
 */

import { Injectable, NestMiddleware, HttpException, HttpStatus } from '@nestjs/common'
import { Request, Response, NextFunction } from 'express'
import { TypedConfigService } from '../../config/typed-config.service'

const STATUS_PAGE_URL = 'https://status.boxlite.ai'

@Injectable()
export class MaintenanceMiddleware implements NestMiddleware {
  constructor(private readonly configService: TypedConfigService) {}

  use(req: Request, res: Response, next: NextFunction) {
    const isMaintenanceMode = this.configService.get('maintananceMode')

    if (isMaintenanceMode) {
      throw new HttpException(
        {
          statusCode: HttpStatus.SERVICE_UNAVAILABLE,
          message: `Service is currently under maintenance. Check ${STATUS_PAGE_URL} for updates, or try again later.`,
          error: 'Service Unavailable',
        },
        HttpStatus.SERVICE_UNAVAILABLE,
      )
    }

    next()
  }
}