Skip to content

Instantly share code, notes, and snippets.

@gtranchedone
Created November 26, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtranchedone/6ed6db80a51ba7fa0a6383958f6dd924 to your computer and use it in GitHub Desktop.
Save gtranchedone/6ed6db80a51ba7fa0a6383958f6dd924 to your computer and use it in GitHub Desktop.
Vapor Routes Command Helper
import Console
import Routing
import HTTP
class FakeRouter: RouteBuilder {
public typealias Host = String
public typealias Method = String
public typealias Output = HTTP.Responder
private let console: Terminal
private final var routes: [String] = []
public init() {
console = Terminal(arguments: [])
}
public func add(path: [String], value: Output) {
var computedPath = path
if computedPath.first == "*" { // host == *
computedPath[0] = ""
}
let route = computedPath.joined(separator: "/")
routes.append(route)
}
public func printRoutes() {
guard routes.count > 0 else {
console.error("No routes found")
return
}
console.info("Routes:")
for route in routes {
console.print(route)
}
console.print("")
}
}
let fakeRouter = FakeRouter()
configureRoutes(router: fakeRouter)
fakeRouter.printRoutes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment