diff --git a/Sources/App/Controllers/HealthCheckController.swift b/Sources/App/Controllers/HealthCheckController.swift new file mode 100644 index 000000000..218b4dc65 --- /dev/null +++ b/Sources/App/Controllers/HealthCheckController.swift @@ -0,0 +1,30 @@ +// Copyright Dave Verwer, Sven A. Schmidt, and other contributors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Fluent +import Plot +import Vapor + +enum HealthCheckController { + + @Sendable + static func show(req: Request) async throws -> String { + // A package page query is a good test of whether the site is healthy. + let (_, _) = try await API.PackageController.GetRoute + .query(on: req.db, + owner: "SwiftPackageIndex", + repository: "SemanticVersion") + return "Success" + } +} diff --git a/Sources/App/Core/SiteURL.swift b/Sources/App/Core/SiteURL.swift index a70ad8323..733d683c3 100644 --- a/Sources/App/Core/SiteURL.swift +++ b/Sources/App/Core/SiteURL.swift @@ -134,6 +134,7 @@ enum SiteURL: Resourceable, Sendable { case stylesheets(String) case supporters case tryInPlayground + case healthCheck case validateSPIManifest var path: String { @@ -254,6 +255,9 @@ enum SiteURL: Resourceable, Sendable { case .tryInPlayground: return "try-in-a-playground" + case .healthCheck: + return "health-check" + case .validateSPIManifest: return "validate-spi-manifest" } @@ -276,6 +280,7 @@ enum SiteURL: Resourceable, Sendable { .siteMapStaticPages, .supporters, .tryInPlayground, + .healthCheck, .validateSPIManifest: return [.init(stringLiteral: path)] diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index aafa25a1d..62266338a 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -128,6 +128,10 @@ func routes(_ app: Application) throws { app.get(SiteURL.supporters.pathComponents, use: SupportersController.show).excludeFromOpenAPI() } + do { // Uptime check + app.get(SiteURL.healthCheck.pathComponents, use: HealthCheckController.show).excludeFromOpenAPI() + } + do { // spi.yml validation page app.get(SiteURL.validateSPIManifest.pathComponents, use: ValidateSPIManifestController.show) .excludeFromOpenAPI()