-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.init.lua
More file actions
104 lines (83 loc) · 2.94 KB
/
.init.lua
File metadata and controls
104 lines (83 loc) · 2.94 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package.path = package.path .. ";.lua/?.lua"
package.path = package.path .. ";app/controllers/?.lua;/zip/app/controllers/?.lua"
package.path = package.path .. ";app/models/?.lua;/zip/app/models/?.lua"
package.path = package.path .. ";app/cronjobs/?.lua;/zip/app/cronjobs/?.lua"
package.path = package.path .. ";config/?.lua;/zip/config/?.lua"
-- OTP = require("otp") -- OTP functions
require("utilities")
require("routes")
local I18nClass = require("i18n")
I18n = I18nClass.new("en")
ProgramMaxPayloadSize(10485760) -- 10 MB
-- DB connection
--local db_config = DecodeJson(LoadAsset("config/database.json"))
--InitDB(db_config)
Views = {}
IsApi = false -- set it to true to return json for 404 errors
-- Preload Font assets for PDF generation
Resources = {
["fonts/TitilliumWeb-Regular.ttf"] = LoadAsset("fonts/TitilliumWeb-Regular.ttf"),
["fonts/TitilliumWeb-Regular.json"] = LoadAsset("fonts/TitilliumWeb-Regular.json"),
["fonts/TitilliumWeb-Bold.ttf"] = LoadAsset("fonts/TitilliumWeb-Bold.ttf"),
["fonts/TitilliumWeb-Bold.json"] = LoadAsset("fonts/TitilliumWeb-Bold.json")
}
-- LastModifiedAt is used to cache the last modified time of the assets
-- so that we can use it to send the correct last modified time to the client
-- and avoid sending the whole file to the client
LastModifiedAt = {}
function OnServerStart()
LoadPublicAssetsRecursively("public")
if BeansEnv == "production" then
LoadViewsRecursively("app/views")
end
end
function OnServerReload() end
function OnServerHeartbeat()
-- It will run in daemon mode
LoadCronsJobs()
end
function OnWorkerStart()
-- Uncomment code if you use SQLite
-- HandleSqliteFork(db_config) -- you can remove it if you do not use SQLite
end
-- OnError hook
function OnError(status, message, details)
-- Define the error for an API
-- WriteJSON({ status = status, message = message })
-- Define the error page via a page with a layout
Params.status = status
Params.message = message
Params.details = details
Params.env = BeansEnv
SetStatus(status)
Page("errors/index", "app")
end
-- OnHttpRequest hook
function OnHttpRequest()
Blocks = {}
-- local redis = require "db.redis"
-- Redis = redis.connect()
Params = GetParams()
PrepareMultiPartParams() -- if you handle file uploads
SetDevice() -- comment if you do not need this feature
-- Uncomment code if you use ArangoDB
-- if Adb then
-- Adb.primary:RefreshToken() -- reconnect to arangoDB if needed
-- end
-- Uncomment code if you use surrealdb
-- if (db_config ~= nil and db_config["engine"] == "surrealdb") then
-- Surreal.refresh_token(db_config[BeansEnv]) -- reconnect to surrealdb if needed
-- end
DefineRoute(GetPath(), GetMethod())
HandleRequest()
-- Uncomment if you use redis
-- unix.close(Redis.network.socket)
end
function SetDevice()
local user_agent = GetHeader("User-Agent")
Params.request = { variant = "" }
local preg = assert(re.compile("iPhone"))
if preg:search(user_agent) then
Params.request.variant = "iphone"
end
end