Swiftpack.co - Package - nodes-vapor/template

Nodes Vapor Template

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

A Vapor template for convenient and fast scaffolding 🏎

📦 Installation

Creating a project

You can create a new project using the Vapor toolbox.

vapor new MyApp --template=nodes-vapor/template

Getting started 🚀

Project name

Before building your project you need to change the name of the project in Package.swift. Look for name: "NodesTemplate" and adjust it to fit your project.

Environment variables

Before running your project, you need to make sure you have the following environment variables set up. For more information on how do this, have a look at our guide here. All the different keys for environment variables are defined in Utilities/EnvironmentKey.swift.

Alternatively use the included .env.example file. Copy the file to .env, enable your required environment variables and add their values.

Make sure to use unique and strong secrets for the signer keys (ie. the keys ending in _SIGNER_KEY). The keys should be unique within and across environments and projects. To generate the keys you can issue the following terminal command: openssl rand -hex 64.


These are project-specific values such as the name of the project (e.g. "My Blog") and the url of the current environment (e.g. http://my-blog.com).


For MySQL you can either use a connection string (using the DATABASE_URL key) or you can supply hostname, username, password and database individually. These will be set automatically on Vapor Cloud, but they will need to be set when running locally.


Similar to MySQL, you can either use a connection string (using the REDIS_URL key) or you can supply hostname and database individually. These will be set automatically on Vapor Cloud, but they will need to be set when running locally.


In order to send out emails using Mailgun, the Mailgun environment variables need to be set.

JWT Keychain

For generating tokens, a couple of signers need to be set for JWT Keychain. These can be generated by using openssl rand -base64 32. Remember to generate different values for each environment.

Admin Panel

Similar to JWT Keychain, Admin Panel also needs a signer to be set.


For handling reset of passwords, Reset also needs a couple of signers to be set (similar to JWT Keychain).

Nodes SSO

To enable Nodes SSO on Admin Panel the project needs to be created on Ournodes (private link) and the environment variables needs to be set up in the project. Be aware when using SSO locally to specify the PROJECT_URL environment variable with http


To support error reporting to Bugsnag, a project needs to be created on our organization and the API key needs to be added to the project.


Remember to update configure.swift and set the correct pathTemplate for the S3Driver. If you're deploying to Vapor Cloud, then nodestemplate should be replaced by your app name on Vapor Cloud. If you're deploying to somewhere else than Vapor Cloud, you might want to change the template pattern.


The internal HealthCheck package provides a convenient HealthCheck HTTP API based on the proposal Health Check Response Format for HTTP APIs. Out of the box an endpoint /health is exposed, responding with an overview of the system's health:

    "status": "pass",
    "releaseId": "1.0.0",
    "notes": [
        "Checks connection to mysql",
        "Checks connection to redis"
    "checks": {
        "redis": [
                "status": "pass",
                "time": "2019-11-11T15:04:11+0100",
                "componentType": "datastore"
        "mysql": [
                "status": "pass",
                "time": "2019-11-11T15:04:11+0100",
                "componentType": "datastore"
    "version": 1

To override the built in health API:

  • conform your services
extension SomeHealthComponent: HealthComponent { ... }
extension AnotherHealthComponent: HealthComponent { ... }
  • use them with the original route configuration in App/Setup/routes.swift
try router.useHealthAPIRoutes(
    for: [
    on: container

Project layout 🗂

This project template aims to follow the official Vapor Style guidelines, with some minor additions/deviations:

  • We have introduced a providers.swift file to handle setting up of providers.
  • We have introduced a leafTags.swift file to handle setting up of Leaf tags.
  • We have a folder named External for any third party integrations (we used to name this folder Services in Vapor 2).

Xcode project 🔨

Vapor toolbox makes it simple to generate a project for Xcode.

vapor xcode -y

Starting your server 🏁

In Xcode, select the Run scheme if you want to startup your server.

Testing your code ⏱

For testing, make sure to have the MyProject-Package scheme selected. Then, you can use ⌘U like usual.

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Steffen.

📄 License

This package is open-sourced software licensed under the MIT license.