55 lines
1.4 KiB
Lua
55 lines
1.4 KiB
Lua
local lapis = require("lapis")
|
|
local app = lapis.Application()
|
|
local constants = require("constants")
|
|
local babycode = require("lib.babycode")
|
|
local html_escape = require("lapis.html").escape
|
|
local config = require("lapis.config").get()
|
|
|
|
local db = require("lapis.db")
|
|
-- sqlite starts without foreign key enforcement
|
|
db.query("PRAGMA foreign_keys = ON")
|
|
|
|
local util = require("util")
|
|
|
|
app:enable("etlua")
|
|
app.layout = require "views.base"
|
|
|
|
local function inject_constants(req)
|
|
req.constants = constants
|
|
math.randomseed(os.time())
|
|
req.__cachebust = math.random(99999)
|
|
req.__commit = config.commit
|
|
end
|
|
|
|
local function inject_methods(req)
|
|
req.avatar_url = util.get_user_avatar_url
|
|
req.ntob = function(_, v)
|
|
return util.ntob(v)
|
|
end
|
|
req.PermissionLevelString = constants.PermissionLevelString
|
|
req.infobox_message = function (_, s)
|
|
return util.infobox_message(s)
|
|
end
|
|
|
|
req.babycode_to_html = function (_, bb)
|
|
return babycode.to_html(bb, html_escape)
|
|
end
|
|
|
|
util.pop_infobox(req)
|
|
end
|
|
|
|
app:before_filter(inject_constants)
|
|
app:before_filter(inject_methods)
|
|
|
|
app:include("apps.users", {path = "/user"})
|
|
app:include("apps.topics", {path = "/topics"})
|
|
app:include("apps.threads", {path = "/threads"})
|
|
app:include("apps.mod", {path = "/mod"})
|
|
app:include("apps.post", {path = "/post"})
|
|
|
|
app:get("/", function(self)
|
|
return {redirect_to = self:url_for("all_topics")}
|
|
end)
|
|
|
|
return app
|