2020-09-22 16:18:12 +02:00
|
|
|
-- the rewrite rule for the framework
|
|
|
|
-- should be something like this
|
|
|
|
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
|
|
|
|
-- some global variables
|
2023-04-26 18:51:03 +02:00
|
|
|
package.path = _SERVER["LIB_DIR"].."/lua/?.lua"
|
|
|
|
require("silk.api")
|
|
|
|
-- crypto lib
|
|
|
|
enc = require("enc")
|
|
|
|
WWW_ROOT = __ROOT__.."/talk"
|
2023-05-22 13:53:41 +02:00
|
|
|
DB_LOC="/opt/www/databases"
|
|
|
|
DB_FILE = DB_LOC.."/quicktalk.db"
|
2020-09-22 16:18:12 +02:00
|
|
|
function fail(msg)
|
|
|
|
std.json()
|
|
|
|
std.t(JSON.encode({error = msg}))
|
|
|
|
end
|
|
|
|
|
|
|
|
function result(obj)
|
|
|
|
std.json()
|
|
|
|
std.t(JSON.encode({result = obj, error = false}))
|
|
|
|
end
|
|
|
|
DIR_SEP = "/"
|
|
|
|
if HEADER.Host then
|
|
|
|
HTTP_ROOT = "https://" .. HEADER.Host
|
|
|
|
else
|
|
|
|
HTTP_ROOT = "https://talk.iohub.dev"
|
|
|
|
end
|
2023-04-26 18:51:03 +02:00
|
|
|
|
2020-09-22 16:18:12 +02:00
|
|
|
-- class path: path.to.class
|
2023-04-26 18:51:03 +02:00
|
|
|
CONTROLLER_ROOT = "talk.controllers"
|
|
|
|
MODEL_ROOT = "talk.models"
|
2020-09-22 16:18:12 +02:00
|
|
|
-- file path: path/to/file
|
2023-04-26 18:51:03 +02:00
|
|
|
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
|
2020-09-22 16:18:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- registry object store global variables
|
|
|
|
local REGISTRY = {}
|
|
|
|
-- set logging level
|
2023-04-26 18:51:03 +02:00
|
|
|
REGISTRY.logger = Logger:new{ level = Logger.INFO}
|
2020-09-22 16:18:12 +02:00
|
|
|
|
|
|
|
REGISTRY.layout = 'default'
|
|
|
|
REGISTRY.fileaccess = true
|
2023-04-26 18:51:03 +02:00
|
|
|
REGISTRY.db = DBModel:new{db = DB_FILE}
|
2020-09-22 16:18:12 +02:00
|
|
|
REGISTRY.db:open()
|
|
|
|
|
|
|
|
local router = Router:new{registry = REGISTRY}
|
|
|
|
REGISTRY.router = router
|
|
|
|
router:setPath(CONTROLLER_ROOT)
|
|
|
|
-- router:route('edit', 'post/edit', "ALL" )
|
|
|
|
|
|
|
|
std.header("Access-Control-Allow-Origin", "*")
|
|
|
|
std.header("Access-Control-Allow-Methods", "POST")
|
|
|
|
std.header("Access-Control-Allow-Headers", "content-type")
|
|
|
|
|
|
|
|
-- router:route('default', nil)
|
|
|
|
router:delegate()
|
|
|
|
if REGISTRY.db then REGISTRY.db:close() end
|