File: app.lua

package info (click to toggle)
lua-cgi 6.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 956 kB
  • sloc: javascript: 2,216; makefile: 25
file content (38 lines) | stat: -rwxr-xr-x 1,093 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env cgilua.cgi

-- Basic application bootstraper
local name, path_info = cgilua.splitonfirst(cgilua.script_vpath)

if name == nil or name == "" then
  if io.open("index.lua") then
    cgilua.handle("index.lua")
  elseif io.open("index.lp") then
    cgilua.handle("index.lp")
  else
    error("No script defined")
  end
else
  local appdir = CGILUA_APPS.."/"..name
  local appinit = "init.lua"
  lfs.chdir(appdir)

  if io.open(appinit) then
    -- checks for authentication if necessary
    if cgilua.authentication and not cgilua.authentication.username() then
      cgilua.redirect(cgilua.authentication.checkURL())
    else
      -- prepares the application environment
      package.path = CGILUA_APPS.."/"..name.."/lua/?.lua;"..package.path
      cgilua.script_pdir = CGILUA_APPS.."/"..name
      cgilua.script_file = nil
      cgilua.script_vdir = "/"
      cgilua.urlpath = cgilua.urlpath.."/"..name
      cgilua.script_vpath = path_info
      cgilua.app_name = name

      cgilua.doif(appinit)
    end
  else
    cgilua.handle(cgilua.script_pdir..name..path_info)
  end
end