Created
November 26, 2016 15:22
-
-
Save gtranchedone/6ed6db80a51ba7fa0a6383958f6dd924 to your computer and use it in GitHub Desktop.
Vapor Routes Command Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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