(This page is a little out of date.)
There are two parts to execution: initialization and actual response to the request. If you use CGI, the server will initialize a new instance of Sputnik for every request, will get a response from this instance and will then destroy it. With FastCGI and Xavante, the server will initialize an instance of Sputnik when it receives the first request, but will then use the same instance for all subsequent requests.
Initialization
- Your webserver (e.g. Apache) receives a request from the web client.
- The server calls
sputnik.cgi,sputnik.fcgiorsputnik.wsdepending on the URL and the server used. (sputnik.cgiis executed by ~/sputnik/bin/wsapi.cgi,sputnik.fcgiis executed by ~/sputnik/bin/wsapi.fastcgi, andsputnik.wsis executed directly by Xavante.) The three scripts are essentially identical. Each calls sputnik.wsapi_app.new_run_function() which returns a function that answers requests. - sputnik.wsapi_app.new_run_function() calls sputnik.new() to create a new instance of Sputnik, passing to it the configuration parameters.
- sputnik.new() creates a connection to a Saci repository. (See below)
- sputnik.wsapi_app.new_run_function() creates a function that will call run() method on the new Sputnik instance for every request.
Responding to a Request
- Your webserver (e.g. Apache) receives a request from the web client. Depending on the server, it will either initialize a new instance of Sputnik or use the one it already has. In either case, run() method will be called on an instance of sputnik, with the request passed in as a parameter.
- If the request contains a user name and a password, Sputnik uses its "auth" module to try to authenticate the user. (See Authentication.) Otherwise, it checks if the user can be authenticated with a token stored in a cookie.
- Sputnik then figures out what node is requested and gets it from Saci.
- The repository returns a node, as a Lua table. Before returning the node, the repository "activates" it, attaching to it the necessary functions.
- The node is then further "activated" with Sputnik-specific functionality. In particular, Sputnik loads the templates specified in the node and translates them into the chosen interface language.
- Once the node is read, Sputnik determines calls the action that is specified in the request.
- The default action converts the content of the node to HTML using Markdown or one of the alternative text-to-html converters (e.g. "luapod" or "medialike").
- The action returns some content and a content-type.
- The action and content-type are sent back to WSAPI which sends it to the server, which sends it to the client.