Skip to content

Commit

Permalink
Switched to http server
Browse files Browse the repository at this point in the history
  • Loading branch information
givip committed Jul 27, 2018
1 parent 587be73 commit 5d84687
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
.executable(name: "HelloBot", targets: ["HelloBot"])
],
dependencies: [
.package(url: "https://github.com/givip/http.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/http.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/crypto.git", from: "3.1.0"),
.package(url: "https://github.com/vapor/multipart.git", from: "3.0.0"),
.package(url: "https://github.com/IBM-Swift/HeliumLogger.git", from: "1.7.0")
Expand Down
14 changes: 6 additions & 8 deletions Sources/Telegrammer/Network/Webhooks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ class Webhooks: Connection {
guard let ip = bot.settings.webhooksIp,
let url = bot.settings.webhooksUrl,
let port = bot.settings.webhooksPort,
let publicCert = bot.settings.webhooksPublicCert,
let privateKey = bot.settings.webhooksPrivateKey else {
let publicCert = bot.settings.webhooksPublicCert else {
throw CoreError(identifier: "Webhooks",
reason: "Initialization parameters wasn't found in enviroment variables")
}
let tlsConfig = TLSConfiguration.forServer(certificateChain: [.file(publicCert)], privateKey: .file(privateKey))


guard let fileHandle = FileHandle(forReadingAtPath: publicCert) else {
let errorDescription = "Public key '\(publicCert)' for HTTPS server wasn't found"
Log.error(errorDescription)
Expand All @@ -52,14 +50,14 @@ class Webhooks: Connection {
let params = Bot.SetWebhookParams(url: url, certificate: cert, maxConnections: maxConnections, allowedUpdates: nil)
return try bot.setWebhook(params: params).flatMap { (success) -> Future<Void> in
Log.info("setWebhook request result: \(success)")
return try self.listenWebhooks(on: ip, port: port, tlsConfig: tlsConfig).then { $0.onClose }
return try self.listenWebhooks(on: ip, port: port).then { $0.onClose }
}
}

private func listenWebhooks(on host: String, port: Int, tlsConfig: TLSConfiguration) throws -> Future<HTTPServer> {
return HTTPServer.start(hostname: host, port: port, responder: dispatcher, tlsConfig: tlsConfig, on: worker)
private func listenWebhooks(on host: String, port: Int) throws -> Future<HTTPServer> {
return HTTPServer.start(hostname: host, port: port, responder: dispatcher, on: worker)
.do { (server) in
Log.info("HTTPS server started on: \(host):\(port)")
Log.info("HTTP server started on: \(host):\(port)")
self.server = server
self.running = true
}
Expand Down

0 comments on commit 5d84687

Please sign in to comment.