-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add grouping of routes by path prefix (#58)
- Loading branch information
1 parent
19bf5d5
commit 48beccc
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extension Application { | ||
/// Groups a set of endpoints by a path prefix. | ||
/// All endpoints added in the `configure` closure will | ||
/// be prefixed, but none in the handler chain that continues | ||
/// after the `.grouped`. | ||
/// | ||
/// - Parameters: | ||
/// - pathPrefix: The path prefix for all routes | ||
/// defined in the `configure` closure. | ||
/// - configure: A closure for adding routes that will be | ||
/// prefixed by the given path prefix. | ||
/// - Returns: This application for chaining handlers. | ||
@discardableResult | ||
public func grouped(_ pathPrefix: String, configure: (Application) -> Void) -> Self { | ||
Services.router.pathPrefixes.append(pathPrefix) | ||
configure(self) | ||
_ = Services.router.pathPrefixes.popLast() | ||
return self | ||
} | ||
} |
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
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