Initial Commit

This commit is contained in:
2020-11-11 14:49:55 -08:00
commit 4f1cddbfdd
466 changed files with 101572 additions and 0 deletions

View File

View File

@@ -0,0 +1,7 @@
import Foundation
import Vapor
struct Config: Codable {
let title: String
let services: [String:[[String:String]]]
}

View File

@@ -0,0 +1,17 @@
import Vapor
import Leaf
import LeafErrorMiddleware
// configures your application
public func configure(_ app: Application) throws {
// Serve files from /Public
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.middleware.use(LeafErrorMiddleware())
// Configure Leaf
LeafOption.caching = app.environment.isRelease ? .default : .bypass
app.views.use(.leaf)
// Register routes
try routes(app)
}

7
Sources/App/isItUp.swift Normal file
View File

@@ -0,0 +1,7 @@
import Foundation
import Vapor
struct isItUp: Codable {
let isitdown: Bool
let response_code: Int
}

21
Sources/App/routes.swift Normal file
View File

@@ -0,0 +1,21 @@
import Vapor
import Foundation
import Leaf
func routes(_ app: Application) throws {
// Render home page when root domain is loaded
app.get { req -> EventLoopFuture<View> in
let fileData = try String(contentsOfFile: "\(app.directory.resourcesDirectory)/config.json").data(using: .utf8)
let config: Config = try! JSONDecoder().decode(Config.self, from: fileData!)
return req.view.render("home", ["config": config])
}
app.get("status", ":url") { req -> EventLoopFuture<[String: String]> in
let url = URL(string: req.parameters.get("url")!)
return req.client.get("https://isitdown.site/api/v3/\(url!)").flatMapThrowing { res in
try res.content.decode(isItUp.self)
}.map { json in
["down": String(json.isitdown), "code": String(json.response_code)]
}
}
}