Apple Swift based HTTP server. The answer for a Swift based, turn key, crash resilient, high scale, and production grade web server.
:raising_hand: Hey there!
Please note: This project is still in Alpha Version and we’re actively working on forking over a lot of nifty features from SwiftEngine to make it compatible with SwiftNIO. We appreciate any contributors or testers joining our project!
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
What are the dependencies we need to get this to work?
OS | Version |
---|---|
macOS | 10.13+ |
Ubuntu | 14.04, 16.04, 16.10 |
git clone https://github.com/swiftengine/SwiftEngine.git
cd
to SwiftEngine
directory and run sudo ./install.sh
./run.sh
This should start the server running and listening on port 8887
Programming your site:
mypage.swift
file within the /var/swiftengine/www/
directory (see example below)http://<machine_ip>:8887/mypage
(by default this is localhost:8887
)That's it! No compilation or dealing with shell dumps required! Your requested endpoints will be automagically compiled during the first request, and results will be shown.
Any swift file you place in /var/swiftengine/www
will be accessible through the browser without the .swift
extension.
Read more about SwiftEngine's autonomous system and routing logic (here)
.swift
file :trophy:// Import SwiftEngine essentials
import SwiftEngine
// specify other required files for this file
//se: require /common.swift
// Entry Point function; where all code begins
func entryPoint(ctx: RequestContext) {
// add GET handlers to the request context
ctx.addHandler(forMethod:"GET", withRoute:"*"){
req, res in
res.write("Hello from SwiftEngine!")
}
// add POST handlers to the request context
ctx.addHandler(forMethod:"POST", withRoute:"*"){
req, res in
res.write("Handle for POST request method")
}
// add catch-all handlers to the request context
ctx.addHandler(forMethod:"*", withRoute:"*"){
req, res in
res.write("Handle for catch-all")
}
}
We would love to hear your thoughts and feedback about SwiftEngine. If you would like to contribute to our project or have an issue you would like to open, please visit our CONTRIBUTING document for more details.
This project is licensed under the Mozilla Public License Version 2.0 - see the LICENSE file for details