Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Sources/App/Controllers/HealthCheckController.swift
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 5 additions & 0 deletions Sources/App/Core/SiteURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ enum SiteURL: Resourceable, Sendable {
case stylesheets(String)
case supporters
case tryInPlayground
case healthCheck
case validateSPIManifest

var path: String {
Expand Down Expand Up @@ -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"
}
Expand All @@ -276,6 +280,7 @@ enum SiteURL: Resourceable, Sendable {
.siteMapStaticPages,
.supporters,
.tryInPlayground,
.healthCheck,
.validateSPIManifest:
return [.init(stringLiteral: path)]

Expand Down
4 changes: 4 additions & 0 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading