Skip to content

Commit

Permalink
rename and generalize setup forwarding to use a container instead of …
Browse files Browse the repository at this point in the history
…a request so we can setup forwarding in boot
  • Loading branch information
twof committed May 1, 2018
1 parent 2e799e7 commit 70bb147
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
71 changes: 49 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,62 @@
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "038e30ec9004fb1915d14d964a3facc1ec5c80f4",
"version": "3.0.0"
"revision": "30f102dcf4d18862a14df9f65c4b91d117005926",
"version": "3.0.1"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "2ad95efabedc228ddbadee1974f6bbaac6c89abd",
"version": "3.0.3"
"revision": "f1c24ab803a7150f31e16ade4557caa504faa142",
"version": "3.1.4"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "e77aa181580b466fb26865918b62973d9fbfaed6",
"version": "3.0.0"
"revision": "346ae2b2ea65a4b6f4985a8e8cb25cf61da549d8",
"version": "3.1.1"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "e594e658cc001e04b8d4ad13881d8714c510f94f",
"version": "1.0.0-rc.2.2.2"
"revision": "0db303439e5ef8b6df50a2b6c4029edddee90cb0",
"version": "1.0.1"
}
},
{
"package": "HTTP",
"repositoryURL": "https://github.com/vapor/http.git",
"state": {
"branch": null,
"revision": "f934c1391c370fbf529bd461b40aa75ce40ce1e5",
"version": "3.0.2"
}
},
{
"package": "Engine",
"repositoryURL": "https://github.com/vapor/engine.git",
"package": "Multipart",
"repositoryURL": "https://github.com/vapor/multipart.git",
"state": {
"branch": null,
"revision": "4846ea9abeb04863f82f618ee8cb22650a82ae3c",
"version": "3.0.0-rc.2.1.1"
"revision": "7778dcb62f3efa845e8e2808937bb347575ba7ce",
"version": "3.0.1"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
"state": {
"branch": null,
"revision": "2fc1d4de22a54848b35ad17b3e7f7816f19ebf90",
"version": "3.0.0-rc.2"
"revision": "3219e328491b0853b8554c5a694add344d2c6cfb",
"version": "3.0.1"
}
},
{
Expand All @@ -69,17 +78,17 @@
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "3275ff7c9c791a628631c2c51b39fd94346b2492",
"version": "1.4.2"
"revision": "902b18df16897da644724bd4b85b4bbe952ac9c6",
"version": "1.5.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "ea006b6368dbd9dbfd297deb6ddb3f070b72d043",
"version": "1.0.1"
"revision": "38955a5f806a952daf2b16fbfe9aa529749cf1dd",
"version": "1.1.0"
}
},
{
Expand All @@ -105,8 +114,17 @@
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "497b987a79291c3743fe4ba6f17eadcdf20c1728",
"version": "1.0.0"
"revision": "43b57b5861d5181b906ac6411d28645e980bb638",
"version": "1.0.1"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "8448fa943057c01220f6a940d3b1b8e9fd92a96e",
"version": "1.0.2"
}
},
{
Expand All @@ -123,8 +141,17 @@
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "c045b8d02e6a135f055e879a9fa789026a0b4e9d",
"version": "3.0.0-rc.2.2.4"
"revision": "c834f9495ff5ab9768b74f5822ff23d795e36922",
"version": "3.0.0-rc.2.8.1"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/vapor/websocket.git",
"state": {
"branch": null,
"revision": "23acd21aa37a200faa2f5d5525c974efa6b5676c",
"version": "1.0.0"
}
}
]
Expand Down
8 changes: 3 additions & 5 deletions Sources/Mailgun/Mailgun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public protocol MailgunProvider: Service {
var apiKey: String { get }
var domain: String { get }
func send(_ content: Mailgun.Message, on req: Request) throws -> Future<Response>
func setupForwarding(setup: RouteSetup, on request: Request) throws -> Future<Response>
func setupForwarding(setup: RouteSetup, with container: Container) throws -> Future<Response>
}

// MARK: - Engine
Expand Down Expand Up @@ -46,7 +46,6 @@ public struct Mailgun: MailgunProvider {
let client = try req.make(Client.self)

return client.post(mailgunURL, headers: headers, content: content).map(to: Response.self) { response in
// can't compare status unless https://github.com/vapor/vapor/issues/1566 is fixed
switch true {
case response.http.status.code == HTTPStatus.ok.code:
return response
Expand All @@ -58,7 +57,7 @@ public struct Mailgun: MailgunProvider {
}
}

public func setupForwarding(setup: RouteSetup, on req: Request) throws -> Future<Response> {
public func setupForwarding(setup: RouteSetup, with container: Container) throws -> Future<Response> {
let authKeyEncoded = try encode(apiKey: self.apiKey)

var headers = HTTPHeaders([])
Expand All @@ -68,12 +67,11 @@ public struct Mailgun: MailgunProvider {

let mailgunURL = "https://api.mailgun.net/v3/routes"

let client = try req.make(Client.self)
let client = try container.make(Client.self)

return client
.post(mailgunURL, headers: headers, content: setup)
.map(to: Response.self) { (response) in
// can't compare status unless https://github.com/vapor/vapor/issues/1566 is fixed
switch true {
case response.http.status.code == HTTPStatus.ok.code:
return response
Expand Down

0 comments on commit 70bb147

Please sign in to comment.