2018-09-05 16:56:04 +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")
|
2018-10-17 19:48:31 +02:00
|
|
|
WWW_ROOT = __ROOT__.."/blog"
|
2023-05-22 13:53:41 +02:00
|
|
|
DB_LOC="/opt/www/databases"
|
|
|
|
DB_FILE = DB_LOC.."/mrsang.db"
|
2023-04-26 18:51:03 +02:00
|
|
|
-- add aditional paths
|
|
|
|
package.path = package.path..";"..WWW_ROOT .. '/?.lua'
|
|
|
|
|
|
|
|
DIR_SEP = "/"
|
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
|
2023-04-26 18:51:03 +02:00
|
|
|
HTTP_ROOT = "https://blog.iohub.dev"
|
2018-10-17 19:48:31 +02:00
|
|
|
end
|
2023-05-22 13:53:41 +02:00
|
|
|
|
2023-04-26 18:51:03 +02:00
|
|
|
CONTROLLER_ROOT = "blog.controllers"
|
|
|
|
MODEL_ROOT = "blog.models"
|
2018-09-05 16:56:04 +02:00
|
|
|
-- file path: path/to/file
|
|
|
|
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
|
2023-04-26 18:51:03 +02:00
|
|
|
POST_LIMIT = 3
|
2018-09-05 16:56:04 +02:00
|
|
|
|
2018-10-05 19:03:29 +02:00
|
|
|
if REQUEST.r then
|
|
|
|
REQUEST.r = REQUEST.r:gsub("%:", "/")
|
2018-02-25 01:57:42 +01:00
|
|
|
end
|
2018-09-05 16:56:04 +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}
|
|
|
|
REGISTRY.db = DBModel:new{db=DB_FILE}
|
2018-09-05 16:56:04 +02:00
|
|
|
REGISTRY.layout = 'default'
|
2018-09-12 18:30:53 +02:00
|
|
|
REGISTRY.fileaccess = true
|
2018-09-05 16:56:04 +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",
|
|
|
|
visibility = {
|
|
|
|
shown = true,
|
|
|
|
routes = {
|
|
|
|
["index/index"] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 12:14:33 +02:00
|
|
|
}
|
|
|
|
router:route('default', default_routes_dependencies )]]
|
2018-09-05 16:56:04 +02:00
|
|
|
router:remap("index", "post")
|
|
|
|
router:remap("r", "post")
|
|
|
|
router:delegate()
|
|
|
|
if REGISTRY.db then REGISTRY.db:close() end
|
|
|
|
|