moonbridge

changeset 26:19a6d18bf34e v0.2

Added some comments to example_application.lua
author jbe
date Fri Jan 30 11:45:12 2015 +0100 (2015-01-30)
parents 2916ad931f7e
children 82987fca10e6
files example_application.lua
line diff
     1.1 --- a/example_application.lua	Fri Jan 30 00:27:28 2015 +0100
     1.2 +++ b/example_application.lua	Fri Jan 30 11:45:12 2015 +0100
     1.3 @@ -3,10 +3,11 @@
     1.4  
     1.5  local http = require "moonbridge_http"
     1.6  
     1.7 +-- preparation before forking:
     1.8  local documents = {}
     1.9  for i, document_name in ipairs{"example_webpage.html", "example_webpage.css"} do
    1.10    local file = assert(io.open(document_name))
    1.11 -  documents[document_name] = file:read("*a")
    1.12 +  documents[document_name] = file:read("*a")  -- store file contents in memory
    1.13    file:close()
    1.14  end
    1.15  
    1.16 @@ -49,6 +50,7 @@
    1.17    
    1.18    -- preparation of process (executed after fork)
    1.19    prepare = function()
    1.20 +    -- e.g. open database connection
    1.21    end,
    1.22    
    1.23    -- connection handler
    1.24 @@ -77,10 +79,9 @@
    1.25          else
    1.26            local document_name = request.path
    1.27            local document_extension = string.match(document_name, "%.([^.])$")
    1.28 -          local document = documents[document_name]
    1.29 +          local document = documents[document_name]  -- loads file contents from memory
    1.30            if document then
    1.31              request:send_status("200 OK")
    1.32 -
    1.33              if document_extension == "html" then
    1.34                request:send_header("Content-Type", "text/html; charset=UTF-8")
    1.35              elseif document_extension == "css" then
    1.36 @@ -151,6 +152,7 @@
    1.37      
    1.38    -- executed on process termination
    1.39    finish = function()
    1.40 +    -- e.g. close database connection
    1.41    end
    1.42  }
    1.43  

Impressum / About Us