Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Feb 16, 2017
2 parents 47c4224 + a9d969c commit 7eb889f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Sources/connect/Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion Sources/express/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions Sources/express/RouteKeeper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 2 additions & 0 deletions Sources/express/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7eb889f

Please sign in to comment.