SwiftMetrics does not provide any security, however, it can easily be used in an already secure environment.

This article securing-kitura-part-1-enabling-ssltls-on-your-swift-server/ details how to configure Kitura to use SSL/TLS.

This article on SwiftMetrics details how to use SwiftMetrics with Kitura.

Combining the articles will enable you to use SwiftMetrics in a secure Kitura environment. I would recommend reading each article in full for details of how to set up keys and certificates.

Here is a simple example of the code you will end up with when running on macOS.


import SwiftMetrics
import SwiftMetricsDash
import Kitura
let router = Router()

// Enable SwiftMetrics Monitoring
let sm = try SwiftMetrics()   

// Activate the Swift Metrics dashboard passing it the router to use
let _ = try SwiftMetricsDash(swiftMetricsInstance: sm, endpoint: router)
 
let myCertKeyFile = "/tmp/Creds/cert.pfx"
let mySSLConfig =  SSLConfig(withChainFilePath: myCertKeyFile,
                             withPassword: "password",
                             usingSelfSignedCerts: true)
router.get("/") {
    request, response, next in
    response.send("Hello, World!")
    next()
}
 
Kitura.addHTTPServer(onPort: 8090, with: router, withSSL: mySSLConfig)
Kitura.run()

Leave a Reply