Skip to content

letsdiscodev/example-swift-vapor-site

 
 

Repository files navigation

Swift Vapor Hello World Example for Disco

A minimal Swift web application using the Vapor framework that serves a simple "Hello, World!" page, designed to be deployed using Disco.

Features

  • Simple "Hello, World!" response at /
  • Health check endpoint at /health
  • Built with Swift's modern concurrency (async/await)
  • Optimized for deployment with Disco
  • Minimal dependencies and lightweight structure

Prerequisites

Quick Start

1. Clone and Setup

git clone <your-repo-url>
cd disco-example-swift-vapor-site

2. Install Dependencies

swift package resolve

3. Run Locally

swift run App

The server will start on http://localhost:8080. You should see:

  • http://localhost:8080/ → "Hello, World!"
  • http://localhost:8080/health{"status": "ok"}

Deployment with Disco

Prerequisites for Deployment

  1. Server Setup: You need a server you can SSH into (VPS from Hetzner, Digital Ocean, or even a Raspberry Pi)
  2. Domain Name: Register a domain with providers like Porkbun, Namecheap, or easydns.com
  3. Disco Installation: Install Disco on your server following the documentation

Deploy Your App

  1. Add your project to Disco:
disco projects:add \
    --name swift-hello-world \
    --github yourusername/disco-example-swift-vapor-site \
    --domain your-domain.com
  1. Deploy by pushing to GitHub:
git add .
git commit -m "Initial commit"
git push origin main

Your app will be automatically built and deployed! 🚀

Monitor Deployment

# View deployment logs
disco deploy:output --project swift-hello-world

# Check project status
disco projects:list

Project Structure

disco-example-swift-vapor-site/
├── Package.swift              # Swift Package Manager configuration
├── Sources/
│   └── App/
│       └── main.swift        # Main application entry point
├── disco.json                # Disco deployment configuration
├── Dockerfile                # Container configuration for deployment
├── README.md                 # This file
└── .gitignore               # Git ignore rules

Configuration

Environment Variables

  • PORT - Server port (defaults to 8080)

Disco Configuration

The disco.json file configures the deployment:

{
    "version": "1.0",
    "services": {
        "web": {
            "port": 8080
        }
    }
}

Development

Adding New Routes

Edit Sources/App/main.swift to add new routes:

app.get("about") { req async -> String in
    "About page"
}

Testing

Test your application locally:

# Run the app
swift run App

# In another terminal, test endpoints
curl http://localhost:8080/
curl http://localhost:8080/health

Troubleshooting

Build Issues

  • Ensure you have Swift 5.10+ installed: swift --version
  • Clear package cache: swift package clean
  • Resolve dependencies: swift package resolve

Deployment Issues

  • Check deployment logs: disco deploy:output --project your-project-name
  • Verify your disco.json configuration
  • Ensure your server meets the system requirements

Why Disco?

  • Cost Effective: Host multiple sites for a single fee instead of paying per project
  • Lightning Fast: Deployments in seconds, not minutes
  • Simple Setup: Push to GitHub and your changes go live automatically
  • Own Your Infrastructure: No vendor lock-in, deploy to your own servers

Learn More

License

This project is provided as an example and is free to use and modify.

About

Example Swift Vapor website for Disco

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 45.3%
  • Swift 32.1%
  • Dockerfile 22.6%