Skip to content

Commit

Permalink
update star node handler. thanks @KenLau
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Feb 4, 2016
1 parent be28c2f commit 5c2621f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Sources/NodeRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,19 @@ class NodeRouter: RouterDriver {
return key.characters.first == ":"
}

var child: Node?

if let variableNode: (key: String, node: Node) = variableNodes.first {
//get rid of `:`
var key = variableNode.key
key.removeAtIndex(key.startIndex)

request.parameters[key] = path
child = variableNode.1
return self.search(variableNode.node, paths: paths, request: request)
} else if let pathNode = node.nodes[path] {
child = pathNode
} else if let startNode = node.nodes["*"] {
child = startNode
}

if let child = child {
return self.search(child, paths: paths, request: request)
return self.search(pathNode, paths: paths, request: request)
} else if let starNode = node.nodes["*"] {
return starNode.handler //thanks @KenLau
} else {
return nil
}

return nil
}
}

0 comments on commit 5c2621f

Please sign in to comment.