# Lighttpd modules needed by WebMCP
server.modules += (
  "mod_cgi",
  "mod_alias",
  "mod_setenv",
  "mod_rewrite",
  "mod_redirect",
 )

# Enable CGI-Execution of *.lua files through lua binary
cgi.assign += ( ".lua" => "/__INSERT_LOCAL_FILE_PATH_TO_LUA_BINARY_HERE__/lua" )

# Connect external URLs to server static files and the webmcp cgi interface
alias.url += (
  "/webmcp-demo/static/" => "/__INSERT_LOCAL_FILE_PATH_TO_DEMO_APPLICATION_HERE__/static/",
  "/webmcp-demo/"        => "/__INSERT_LOCAL_FILE_PATH_TO_WEBMCP_FRAMEWORK_HERE__/cgi-bin/" )

# Configure environment for demo application    
$HTTP["url"] =~ "^/webmcp-demo/" {
  setenv.add-environment += (
    "WEBMCP_APP_BASEPATH" => "/__INSERT_LOCAL_FILE_PATH_TO_DEMO_APPLICATION_HERE__",
    "WEBMCP_CONFIG_NAME"  => "demo")
}

# URL beautification
url.rewrite-once += (

  # do not rewrite static URLs
      "^/webmcp-demo/static/(.*)$" =>
      "/webmcp-demo/static/$1",

  # dynamic URLs
      "^/webmcp-demo/([^\?]*)(\?(.*))?$" =>
      "/webmcp-demo/webmcp-wrapper.lua?_webmcp_path=$1&$3",

)

# Redirects for URLs without trailing slashes
url.redirect += (
  # base URL without trailing slash
      "^/webmcp-demo$" => "/webmcp-demo/",
  # module base URL without trailing slash
      "^/webmcp-demo/([^/\?]+)$" => "/webmcp-demo/$1/",
)
