diff --git a/.travis.yml b/.travis.yml index b86fb36..af7368a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-3.0.2-release/ubuntu1404/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu14.04.tar.gz" sudo: required - os: osx - osx_image: xcode8 + osx_image: xcode8.2 before_install: - ./xcconfig/before-install.sh diff --git a/README.md b/README.md index 9502a72..b8a6eb4 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ an email to tell us why this is crap (or not?). | OS | Swift | Xcode | Make | SPM | | ----- | ------ | --------------------------------------------------------- | ---- | ---- | | macOS | 3.0 | [Xcode 8](https://developer.apple.com/xcode/download/) | 👍🏻 | 👍 | -| tuxOS | [3.0.1](https://swift.org/download/#releases) | | 👍🏻 | 👍 | +| tuxOS | [3.0.2](https://swift.org/download/#releases) | | 👍🏻 | 👍 | With the release of Swift 3 Noze.io drops support for Swift 2.x. If you are still interested in using it with 2.x, the last release is still available diff --git a/Sources/connect/Connect.swift b/Sources/connect/Connect.swift index 6707bb3..a947270 100644 --- a/Sources/connect/Connect.swift +++ b/Sources/connect/Connect.swift @@ -89,7 +89,10 @@ public class Connect { response.writeHead(404) response.end() } - var next : Next? = { _ in } // cannot be let as it's self-referencing + + guard !matchingMiddleware.isEmpty else { return endNext() } + + var next : Next? = { _ in } // cannot be let as it's self-referencing var i = 0 // capture position in matching-middleware array (shared) next = { diff --git a/Sources/express/Route.swift b/Sources/express/Route.swift index 48e61c7..bce2d2f 100644 --- a/Sources/express/Route.swift +++ b/Sources/express/Route.swift @@ -64,7 +64,8 @@ public struct Route: MiddlewareObject { response res: ServerResponse, next cb: @escaping Next) { - guard matches(request: req) else { cb(); return } + guard matches(request: req) else { return cb() } + guard !self.middleware.isEmpty else { return cb() } // push route state let oldParams = req.params diff --git a/Sources/express/RouteKeeper.swift b/Sources/express/RouteKeeper.swift index 31de220..aa8c8ab 100644 --- a/Sources/express/RouteKeeper.swift +++ b/Sources/express/RouteKeeper.swift @@ -68,3 +68,55 @@ public extension RouteKeeper { return self } } + +public extension RouteKeeper { + // Directly attach MiddlewareObject's as Middleware. That is: + // let app = express() + // let admin = express() + // app.use("/admin", admin) + + @discardableResult + public func use(_ middleware: MiddlewareObject) -> Self { + return use(middleware.middleware) + } + + @discardableResult + public func use(_ p: String, _ middleware: MiddlewareObject) -> Self { + return use(p, middleware.middleware) + } + + @discardableResult + public func all(_ p: String, _ middleware: MiddlewareObject) -> Self { + return all(p, middleware.middleware) + } + + @discardableResult + public func get(_ p: String, _ middleware: MiddlewareObject) -> Self { + return get(p, middleware.middleware) + } + + @discardableResult + public func post(_ p: String, _ middleware: MiddlewareObject) -> Self { + return post(p, middleware.middleware) + } + + @discardableResult + public func head(_ p: String, _ middleware: MiddlewareObject) -> Self { + return head(p, middleware.middleware) + } + + @discardableResult + public func put(_ p: String, _ middleware: MiddlewareObject) -> Self { + return put(p, middleware.middleware) + } + + @discardableResult + public func del(_ p: String, _ middleware: MiddlewareObject) -> Self { + return del(p, middleware.middleware) + } + + @discardableResult + public func patch(_ p: String, _ middleware: MiddlewareObject) -> Self { + return patch(p, middleware.middleware) + } +} diff --git a/Sources/express/Router.swift b/Sources/express/Router.swift index 842305e..2e875e4 100644 --- a/Sources/express/Router.swift +++ b/Sources/express/Router.swift @@ -24,6 +24,8 @@ open class Router: MiddlewareObject { response res : ServerResponse, next endNext : @escaping Next) { + guard !self.routes.isEmpty else { return endNext() } + let routes = self.routes // make a copy to protect against modifications var next : Next? = { _ in } // cannot be let as it's self-referencing