While Swiftfire is capable of servicing static websites out-of-the-box, it is possible to add services to the domains without a deep understanding of Swiftfire itself.
Adding a service consists of three steps:
- Create a service
- Register the service
- Assign the service to one or more domains
Creating a service
Each HTTP request results in the activation of a chain of services.
Each service can implement some part of a webserver response.
For example, the first default service is called “Blacklist”. This service checks if the client is on a blacklist, i.e. a list of clients that are not allowed to access to that domain. If this service finds a match, it will tell the service chain handler to stop servicing the request and terminate the chain.
The service signature:
The parameters are:
header: The HTTP header abstracted into a class that allows for easy access to the field elements.
body: The data that associated the request, may be nil.
connection: A connection object that o.a. handles the transfer to/from the client.
domain: A reference to the domain for which the request was made.
chainInfo: A dictionary for communication between services.
response: The response to be send back to the client.
Return value: Indicates if the response chain should continue with the next service in the chain, or if it should abort chain processing. Chain processing should never be aborted, except in specific cases (for example blacklist) or when an error is detected that prevents further processing.
Registering the service
The services are registered in “Service.Registration.swift” by the following code:
To add a service, create a new name for it, and add the service to the list. The sequence is not important, as that will be determined by the next step.
Assigning a service to a domain
Use the SwiftfireConsole to assign services to the domains in the “Services” window:
Drag and drop the services from the right hand table to the table on the left. Be sure to put the services in the correct order.
Services will be executed from top to bottom.
When a service is added it will appear in the table on the right.
To remove a service from a domain, drag it from the left table to the right table.
Changes take effect when the “Update on Swiftfire” button is clicked and the server is switched from “Not Running” to “Running”.