A template Vapor app with nginx frontend.

Overview

vapor-nginx-pg

This is an example Vapor app. It contains the app itself, as well as surrounding components (Postgres database, nginx frontend for providing secure connection), all runnable out of the box with docker compose. It is a good starting point for Vapor development of an API server which you could access from macOS and iOS clients.

The app supports several scenarios. You can run the whole thing built with docker-compose and not worry about the contents of anything. Or, you can run the Vapor app interactively from within Xcode (for development, debugging, testing) while the other components keep running in Docker. These scenarios are discussed below in greater detail.

The goal of this project is to illustrate deployment to your local macOS computer for development and testing. Although some ideas and code here may be suitable for production deployment, there are no guarantees about that, and it hasn’t been reviewed or battle-tested. Use at your own risk.

Getting started

First, install Docker Desktop for macOS. This project may work in other environments, but I have only tested it with Docker Desktop for macOS.

You can then run the app almost out of the box. See the scenarios below.

The one thing that you do need to provide is the private key and certificate for TLS encryption (HTTPS). If you attempt to docker compose up right after cloning this repo, you will see errors about the certificate and key files not found. For security reasons, this project does not ship with a key and certificate: you must generate and provide your own.

Preparing the key and certificate

See this blog post for a discussion of TLS in modern macOS and iOS, and instructions for generating the key and certificate in a way that is acceptable to modern Apple platforms.

Create a temporary working folder. Follow the instructions in the blog post to generate your keys and certificates into that folder, and install the CA certificates into your devices. You will end up with a bunch of files, but only a few are relevant for this project.

After completing the generation process, do the following.

  1. Add the development CA certificate to the server certificate, so that you end up with a single file containing the certificate chain. cat development-ca.crt >> development.crt.
  2. Copy development.crt and development.key into frontend/nginx and frontend-xcode/nginx, next to nginx.conf that is already present in those folders.

That’s it. You can now run the system with docker compose up (add -d flag to daemonize if you want).

Common scenarios

Here are the scenarios that I have considered and tested for this project, and how to access various resources in each case.

Developing your Vapor project in Xcode

What: You need to implement some business logic and functionality in Vapor. Just check out this project, and start modifying the Vapor part of the code. You can open the backend folder with Xcode and just run the project.

How: Just clone this repo, provide the key and certificate as discussed above, and run docker compose up -d. Then, run the project in Xcode. You can access the server with HTTPS at https://localhost:8082 or https://[your-mac-hostname-or-ip]:8082. You can do this from any macOS or iOS device and it should just work, given that you have installed the development CA certificate with the above instructions. Inspect the database at the standard location localhost:5432 with your favorite PostgreSQL client.

As an exercise, run the Vapor app in Xcode, and then run this cURL command from your Terminal:

curl -X POST --header "Content-type: application/json" --data '{"title": "first todo"}'  -v https://localhost:8082/todos

Observe the cURL output, your Docker Desktop console, Xcode console, and database content change.

Running tests

What: You should write tests for your Vapor project. Run these tests with standard Xcode facilities. The tests run against a separate PostgreSQL database instance that is distinct from your application database, since the data is cleared out at each test invocation.

How: Use standard Xcode test running. The one thing to do is to point the tests to a different database port so that they work against the testing database instead of the real database. The easiest way to do that is to provide the environment variable via the Xcode testing scheme.

Database port for testing

You can access the testing database directly with your favourite PostgreSQL client at localhost:5433.

Using the Vapor server as-is

What: It may be that you are not working on the Vapor part of the code at all: you simply need to use the functionality that’s already implemented.

How: This couldn’t be simpler. Just clone this repo and run docker compose up -d. You can then access the server with HTTPS at https://localhost:8081 or https://[your-mac-hostname-or-ip]:8081. You can do this from any macOS or iOS device and it should just work, given that you have installed the development CA certificate with the above instructions. Inspect the database at the standard location localhost:5432 with your favorite PostgreSQL client.

You might also like...
UIKit-based app project template for Swift Playgrounds 4
UIKit-based app project template for Swift Playgrounds 4

playgrounds-uikit-app This is a simplistic sample template for Swift Playgrounds 4 to begin with a UIKit-based app delegate & window scene instead of

A zero-code template app that demonstrates how to use TheraForge's APIs and can be used for fast prototyping
A zero-code template app that demonstrates how to use TheraForge's APIs and can be used for fast prototyping

TheraForge MagicBox 1.0.0-beta The Open TheraForge (OTF) MagicBox app is a template for creating digital health solutions that help people better mana

Template repository for quickly creating boilerplate code for a SwiftUI macOS app.
Template repository for quickly creating boilerplate code for a SwiftUI macOS app.

Sidebar App This is a template repository for quickly creating boilerplate code for a SwiftUI macOS app. License This app is released into the public

This is a template repository for quickly creating boilerplate code for a SwiftUI macOS menu bar app.
This is a template repository for quickly creating boilerplate code for a SwiftUI macOS menu bar app.

Menu Bar App This is a template repository for quickly creating boilerplate code for a SwiftUI macOS menu bar app. License This app is released into t

🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.
🛠 A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern.

Model-View-Presenter template A flexible and easy template created to speed up the development of your iOS application based on the MVP pattern. This

XCode Preview template for UIkit based project.
XCode Preview template for UIkit based project.

SwiftPreview XCode Preview template for UIkit based project. Support custom file template class inherit from UIView and UIViewController. How to use?

The template for Delta Client plugins.

Delta Plugin Template This repository is a template for Delta Client plugins. To create a plugin, create a repo from this template repo and then repla

React Native Template for Taro

React Native Template for Taro requirement taro: @tarojs/cli@^3.2.0 framework: 'react' quick start install react native library install peerDependenci

Xamoom tourism template iOS

xamoom-tourism-template-iOS Pods Install pods via command pod install Buid system Open File - Workpace settings Select Legacy Build System Check Do n

Owner
Jaanus Kase
Jaanus Kase
Scane - MacOS frontend for SANE

SCANE A MacOS frontend for SANE. Did Apple unceremoniously drop support for your

Matt Adam 8 Dec 21, 2022
Cross-platform, sophisticated frontend for the libretro API.

RetroArch is the reference frontend for the libretro API. Popular examples of implementations for this API includes video game system emulators and game engines as well as more generalized 3D programs. These programs are instantiated as dynamic libraries. We refer to these as "libretro cores".

null 7.4k Dec 27, 2022
iOS & tvOS multi-emulator frontend, supporting various Atari, Bandai, NEC, Nintendo, Sega, SNK and Sony console systems

iOS & tvOS multi-emulator frontend, supporting various Atari, Bandai, NEC, Nintendo, Sega, SNK and Sony console systems… Get Started: https://wiki.provenance-emu.com |

Provenance Emu 5.1k Dec 31, 2022
Respresso is a centralized resource manager for shared Android, iOS and Web frontend projects

Introduction Respresso is a centralized resource manager for shared Android, iOS and Web frontend projects. It allows you to simply import the latest

Respresso 10 Nov 8, 2022
Learning iOS Frontend: Aplikasi iOS Pemesanan Makanan dengan SwiftUI, WidgetKit, Google Fonts, dan Assets dari Figma

Foody Aplikasi Foody adalah Aplikasi iOS Pemesanan Makanan dengan SwiftUI, WidgetKit, Google Fonts, dan Assets dari Figma untuk Mempelajari Ilmu Front

DK 10 Aug 20, 2022
VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

Joseph Duffy 23 Nov 4, 2022
A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

Vijay 0 Jan 10, 2022
OpenAPI specification generator for Vapor based Swift projects.

VaporToOpenAPI VaporToOpenAPI is a Swift library which can generate output compatible with OpenAPI version 3.0.1 from Vapor code. You can use generate

null 3 Dec 15, 2022
A dynamic sitemap generator for Vapor

A dynamic sitemap generator for Vapor

Vapor Community 5 Apr 21, 2022
Static Native Template and Dynamic Styling without any other app release

FileManager Project Students and Freshers, Good opportunity for you to learn and contribute in this project. Here you would learn how you can change t

Naveen Chauhan 3 Nov 30, 2021