Skip to content

Server

The server is responsible for accepting connections from clients, parsing their requests, and delivering them a response.

Default

Starting your Droplet with a default server is simple.

import Vapor

let drop = try Droplet()
try drop.run()

The default server will bind to host 0.0.0.0 at port 8080.

Config

If you are using a Config/server.json file, this is where you can easily change your host and port.

{
    "port": "$PORT:8080",
    "host": "0.0.0.0",
    "securityLayer": "none"
}

The default server.json is above. The port with try to resolve the environment variable $PORT or fallback to 8080.

TLS

TLS (formerly SSL) can be configured with a variety of different certificate and signature types.

Verify

Verificiation of hosts and certificates can be disabled. They are enabled by default.

Note: Be extremely careful when disabling these options.

"tls": {
    "verifyHost": false,
    "verifyCertificates": false
}

Certificates

None

"tls": {
    "certificates": "none"
}

Chain

"tls": {
    "certificates": "chain",
    "chainFile": "/path/to/chainfile"
}

Files

"tls": {
    "certificates": "files",
    "certificateFile": "/path/to/cert.pem",
    "privateKeyFile": "/path/to/key.pem"
}

Certificate Authority

"tls": {
    "certificates": "ca"
}

Signature

Self Signed

"tls": {
    "signature": "selfSigned"
}

Signed File

"tls": {
    "signature": "signedFile",
    "caCertificateFile": "/path/to/file"
}

Signed Directory

"tls": {
    "signature": "signedDirectory",
    "caCertificateDirectory": "/path/to/dir"
}

Example

Here is an example server.json file using certificate files with a self signed signature and host verification redundantly set to true.

{
    "port": "8443",
    "host": "0.0.0.0",
    "securityLayer": "tls",
    "tls": {
        "verifyHost": true,
        "certificates": "files",
        "certificateFile": "/vapor/certs/cert.pem",
        "privateKeyFile": "/vapor/certs/key.pem",
        "signature": "selfSigned"
    }
}

Nginx

It is highly recommended that you serve your Vapor project behind Nginx in production. Read more in the deploy Nginx section.