Build your websites in Swift!
Swift is a fantastic language, and now that enthusiasm can spill over into the website domain!
Swiftfire was created with the goal to be able to create websites that are (sever side) completely written with Swift.
The result of this effort is a webserver framework we call Swiftfire.
Out of the box, the Swiftfire framework is a fully functional webserver that can deliver static websites to clients.
But a framework can be extended. Swiftfire uses two methods that allow the insertion of dynamic features into a static website by user written Swift code.
First off, there are ‘Services’. Every domain is implemented as a stack of ‘services’. Once an HTTP request is received for a domain, its services are executed one after the other. Until finally a response is created which is then send back to the client. The static server is in fact a stack of default services that is assigned to each new domain. And of course you can create your own services.
Secondly, there are ‘Functions’. The service that will return a page to the client can scan that page first for occurrences of functions. If a function is found, it will execute that function and replace the function with the code that the function generated. The function itself is a Swift function that must have been registered during startup.
An example: “This page has been returned .functioncall() times”. If I replace the name ‘functioncall’ with the actual name of the function ‘nofPageHits’ the following happens: “This page has been returned 63 times”.
If you are looking at this page on http://swiftfire.nl:6678/index.sf.html then you will see a number between ‘returned’ and ‘times’. If however you are using port 80 (http://swiftfire.nl:80) then you will see the function call itself. Why is that?, because on our server at port 80 the standard Apache webserver is running, while at port 6678 the Swiftfire webserver is running. And Swiftfire will replace the functioncall with the result from the function.
Of course Swiftfire also offers support for multiple domains, HTTPS, sessions, accounts, blacklisting etc etc.
All code is open source. You are encouraged to download the sourcecode from github and customize the Swift code as necessary for your own website/project. Up until version 1.0 is released this will be the only way to install Swiftfire. From v1.0 on, there will be builds that can be downloaded from the AppStore for convenience or non-programmers.
Before you get going please read the readme page to get familiar with some basic terminology and the general design of Swiftfire.
The Swiftfire project is split into smaller projects.
- BRUtils: Mostly type extensions used throughout the project.
- Ascii: Ascii character definitions.
- CAsl: A bridge to allow access to the ASL facility.
- COpenSsl: A bridge to allow access to openSSL v1.1.0.
- KeyedCache: A general purpose dictionary like cache.
- SwifterLog: A general purpose logging utility.
- SwifterJSON: A JSON code interpreter/generator.
- SwifterSockets: A collection of networking utilities at the POSIX level.
- SecureSockets: A collection of networking utilities that implement SSL.
- Http: An API for HTTP messages.
- Html: Some definitions & functions that make creating HTML code easier.
- Swiftfire: The webserver (a GUI-less application).
All of these are open source and can be found on github.