1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-29 02:38:22 +01:00
antd-web-apps/info/router.lua

83 lines
2.3 KiB
Lua
Raw Normal View History

2018-08-23 11:43:42 +02:00
-- the rewrite rule for the framework
-- should be something like this
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
-- some global variables
package.path = _SERVER["LIB_DIR"].."/lua/?.lua"
require("silk.api")
2018-10-17 19:48:31 +02:00
WWW_ROOT = __ROOT__.."/info"
2018-10-19 11:20:56 +02:00
if HEADER.Host then
HTTP_ROOT= "https://"..HEADER.Host
2018-10-17 19:48:31 +02:00
else
HTTP_ROOT = "https://info.iohub.dev"
2018-10-17 19:48:31 +02:00
end
-- TODO remove me
HTTP_ROOT = HTTP_ROOT.."/next/info"
CONTROLLER_ROOT = "info.controllers"
MODEL_ROOT = "info.models"
2018-08-23 11:43:42 +02:00
-- file path: path/to/file
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
-- registry object store global variables
local REGISTRY = {}
-- set logging level
REGISTRY.logger = Logger:new{ level = Logger.INFO}
2022-07-20 12:46:02 +02:00
REGISTRY.users_allowed = { phuong = true, mrsang = true, dany = true }
-- TODO change me
REGISTRY.user = "dany"
REGISTRY.dbfile = "/home/"..REGISTRY.user.."/databases/"..REGISTRY.user..".db"
REGISTRY.db = DBModel:new{db=REGISTRY.dbfile}
2018-08-23 11:43:42 +02:00
REGISTRY.layout = 'default'
2018-09-12 18:30:53 +02:00
REGISTRY.fileaccess = true
2018-08-23 11:43:42 +02:00
REGISTRY.db:open()
local router = Router:new{registry = REGISTRY}
REGISTRY.router = router
router:setPath(CONTROLLER_ROOT)
--router:route('edit', 'post/edit', "ALL" )
-- example of depedencies to the current main route
-- each layout may have different dependencies
local default_routes_dependencies = {
user = {
url = "user/index",
visibility = "ALL"
},
toc = {
url = "toc/index",
2018-08-23 11:43:42 +02:00
visibility = {
shown = true,
routes = {
["index/index"] = true
2018-08-23 11:43:42 +02:00
}
}
}
2018-08-23 11:43:42 +02:00
}
router:route('default', default_routes_dependencies )
2020-06-07 15:20:21 +02:00
BaseController:subclass("NotfoundController",{ registry = {}, models = {} })
function NotfoundController:index(...)
local args = {...}
local user = args[1]:gsub("Controller", ""):lower();
2020-06-17 20:07:50 +02:00
if not REGISTRY.users_allowed[user] then
self:error("404: Controller "..args[1].." not found : "..args[2])
return
end
LOG_DEBUG("Request: %s", REQUEST.r)
REQUEST.r = ulib.trim(REQUEST.r:gsub(user, ""), "/")
2020-06-07 15:20:21 +02:00
if REGISTRY.db then REGISTRY.db:close() end
2020-06-07 19:46:59 +02:00
REGISTRY.user = user
REGISTRY.dbfile = "/home/"..REGISTRY.user.."/databases/"..REGISTRY.user..".db"
REGISTRY.db = DBModel:new{db=REGISTRY.dbfile}
2020-06-07 15:20:21 +02:00
REGISTRY.db:open()
router:delegate()
end
2018-08-23 11:43:42 +02:00
router:delegate()
if REGISTRY.db then REGISTRY.db:close() end