Skip to content

Instantly share code, notes, and snippets.

@edjiang
Last active September 4, 2016 04:39
Show Gist options
  • Save edjiang/7090d5e0ca960d3df7cd721bea67b871 to your computer and use it in GitHub Desktop.
Save edjiang/7090d5e0ca960d3df7cd721bea67b871 to your computer and use it in GitHub Desktop.

Live coding demo for https://speakerdeck.com/edjiang/super-spectacular-server-side-swift

Install Swiftenv

git clone https://github.com/kylef/swiftenv.git ~/.swiftenv

echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile

Install Swift 5-31

swiftenv install DEVELOPMENT-SNAPSHOT-2016-05-31-a

Initialize Project

mkdir HelloWorld
cd HelloWorld
swiftenv local DEVELOPMENT-SNAPSHOT-2016-05-31-a

swift package init --type executable

Add Vapor as Dependency

    dependencies: [
    	.Package(url: "https://github.com/qutheory/vapor.git", majorVersion: 0, minor: 10)
    ]

Open in Xcode

swift package generate-xcodeproj
open HelloWorld.xcodeproj

Code

import Vapor

let app = Application()

app.get("/") { request in
    return "Hello, World!"
}

app.start()

Run the app

Run the HelloWorld target in Xcode, or

swift build
.build/debug/HelloWorld

Deploy to Heroku

git init
heroku create

heroku buildpacks:set https://github.com/kylef/heroku-buildpack-swift
echo 'web: HelloWorld --port=$PORT' >> Procfile

git add .
git commit -m "created project"
git push heroku master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment