Skip to content

Commit

Permalink
Express: allow .use/.get etc for MiddlewareObject's
Browse files Browse the repository at this point in the history
That thing, w/o the need to use .middleware:

  let app   = express()
  let admin = express()
  app.use("/admin", admin)
  • Loading branch information
helje5 committed Feb 8, 2017
1 parent c1d1f6e commit a9d969c
Showing 1 changed file with 52 additions and 0 deletions.
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)
}
}

0 comments on commit a9d969c

Please sign in to comment.