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
3 changes: 2 additions & 1 deletion Sources/Server/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public func configure(_ app: Application) async throws {
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
database: Environment.get("DATABASE_NAME") ?? "vapor_database",
tlsConfiguration: tlsConfiguration
tlsConfiguration: tlsConfiguration,
connectionPoolTimeout: .seconds(10)
), as: .mysql)

app.migrations.add(CreateEntityStorageDbItem())
Expand Down
9 changes: 9 additions & 0 deletions Sources/Server/routes.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import HAImplementations
import HAModels
import OpenAPIVapor
import SQLKit
import Vapor

func routes(_ app: Application) throws {
Expand All @@ -18,6 +19,14 @@ func routes(_ app: Application) throws {
"It works!"
}

authenticatedRoutes.get("health") { req async throws -> HTTPStatus in
guard let sql = req.db as? any SQLDatabase else {
throw Abort(.internalServerError, reason: "Database does not support SQL queries")
}
try await sql.raw("SELECT 1").run()
return .ok
}

authenticatedRoutes.get("config") { req in
let location = await req.application.homeAutomationConfigService.location
let automations = await req.application.homeAutomationConfigService.automations.map(AnyAutomation.create(from:))
Expand Down