Kitura
public class Kitura
A set of helper functions to make it easier to create, start, and stop Kitura based servers.
Usage Example:
In this example, a function called run is created, inside a server Application.swift
file. This will create a Kitura server on the specified port, using the given router and run this created server. This Application.run
function would then be called in your main.swift
file as a non-returning function to initilize your Kitura server.
let router = Router()
let port: Int = 8080
public func run() throws{
...
Kitura.addHTTPServer(onPort: port, with: router)
Kitura.run()
}
-
Add an HTTPServer on a port with a delegate.
The server is only registered with the framework, it does not start listening on the port until
Kitura.run()
orKitura.start()
are called.Usage Example:
Kitura.addHTTPServer(onPort: port, with: router)
Declaration
Swift
public class func addHTTPServer(onPort port: Int, with delegate: ServerDelegate, withSSL sslConfig: SSLConfig?=nil, keepAlive keepAliveState: KeepAliveState = .unlimited, allowPortReuse: Bool = false) -> HTTPServer
Parameters
onPort
The port to listen on.
with
The
ServerDelegate
to use.withSSL
The
sslConfig
to use.keepAlive
The maximum number of additional requests to permit per Keep-Alive connection. Defaults to
.unlimited
. If set to.disabled
, Keep-Alive will not be permitted.allowPortReuse
Determines whether the listener port may be shared with other Kitura instances (
SO_REUSEPORT
). Defaults tofalse
. If the specified port is already in use by another listener that has not allowed sharing, the server will fail to start.Return Value
The created
HTTPServer
. -
Add a FastCGIServer on a port with a delegate.
The server is only registered with the framework, it does not start listening on the port until
Kitura.run()
orKitura.start()
are called.Usage Example:
Kitura.addFastCGIServer(onPort: port, with: router)
Declaration
Swift
public class func addFastCGIServer(onPort port: Int, with delegate: ServerDelegate, allowPortReuse: Bool = false) -> FastCGIServer
Parameters
onPort
The port to listen on.
with
The
ServerDelegate
to use.allowPortReuse
Determines whether the listener port may be shared with other Kitura instances (
SO_REUSEPORT
). Defaults tofalse
. If the specified port is already in use by another listener that has not allowed sharing, the server will fail to start.Return Value
The created
FastCGIServer
. -
Start the Kitura framework.
Usage Example:
Make all registered servers start listening on their port.
Kitura.run()
Note
This function never returns - it should be the last call in yourmain.swift
file.Declaration
Swift
public class func run()
-
Start all registered servers and return.
Usage Example:
Make all registered servers start listening on their port.
Kitura.start()
Declaration
Swift
public class func start()
-
Stop all registered servers.
Usage Example:
Make all registered servers stop listening on their port.
Kitura.stop()
Declaration
Swift
public class func stop(unregister: Bool = true)
Parameters
unregister
If servers should be unregistered after they are stopped (default true).