@@ -4,7 +4,6 @@ package.path = package.path .. ";app/models/?.lua;/zip/app/models/?.lua"
44package.path = package.path .. " ;app/cronjobs/?.lua;/zip/app/cronjobs/?.lua"
55package.path = package.path .. " ;config/?.lua;/zip/config/?.lua"
66
7-
87-- OTP = require("otp") -- OTP functions
98require (" utilities" )
109require (" routes" )
@@ -19,78 +18,76 @@ ProgramMaxPayloadSize(10485760) -- 10 MB
1918-- InitDB(db_config)
2019
2120Views = {}
22- isApi = false
21+ IsApi = false -- set it to true to return json for 404 errors
2322
2423-- LastModifiedAt is used to cache the last modified time of the assets
2524-- so that we can use it to send the correct last modified time to the client
2625-- and avoid sending the whole file to the client
2726LastModifiedAt = {}
2827
2928function OnServerStart ()
30- LoadPublicAssetsRecursively (" public" )
31- if BeansEnv == " production" then
32- LoadViewsRecursively (" app/views" )
33- end
29+ LoadPublicAssetsRecursively (" public" )
30+ if BeansEnv == " production" then
31+ LoadViewsRecursively (" app/views" )
32+ end
3433end
3534
36- function OnServerReload ()
37- end
35+ function OnServerReload () end
3836
3937function OnServerHeartbeat ()
40- LoadCronsJobs ()
38+ LoadCronsJobs ()
4139end
4240
4341function OnWorkerStart ()
44- -- Uncomment code if you use SQLite
45- -- HandleSqliteFork(db_config) -- you can remove it if you do not use SQLite
42+ -- Uncomment code if you use SQLite
43+ -- HandleSqliteFork(db_config) -- you can remove it if you do not use SQLite
4644end
4745
4846-- OnError hook
4947function OnError (status , message , details )
50- -- Define the error for an API
51- -- WriteJSON({ status = status, message = message })
52-
53- -- Define the error page via a page with a layout
54- Params .status = status
55- Params .message = message
56- Params .details = details
57- Params .env = BeansEnv
58- Page (" errors/index" , " app" )
48+ -- Define the error for an API
49+ -- WriteJSON({ status = status, message = message })
50+
51+ -- Define the error page via a page with a layout
52+ Params .status = status
53+ Params .message = message
54+ Params .details = details
55+ Params .env = BeansEnv
56+ Page (" errors/index" , " app" )
5957end
6058
6159-- OnHttpRequest hook
6260function OnHttpRequest ()
61+ -- local redis = require "db.redis"
62+ -- Redis = redis.connect()
6363
64- -- local redis = require "db.redis"
65- -- Redis = redis.connect()
66-
67- Params = GetParams ()
68- PrepareMultiPartParams () -- if you handle file uploads
64+ Params = GetParams ()
65+ PrepareMultiPartParams () -- if you handle file uploads
6966
70- SetDevice () -- comment if you do not need this feature
67+ SetDevice () -- comment if you do not need this feature
7168
72- -- Uncomment code if you use ArangoDB
73- -- if Adb then
74- -- Adb.primary:RefreshToken() -- reconnect to arangoDB if needed
75- -- end
69+ -- Uncomment code if you use ArangoDB
70+ -- if Adb then
71+ -- Adb.primary:RefreshToken() -- reconnect to arangoDB if needed
72+ -- end
7673
77- -- Uncomment code if you use surrealdb
78- -- if (db_config ~= nil and db_config["engine"] == "surrealdb") then
79- -- Surreal.refresh_token(db_config[BeansEnv]) -- reconnect to surrealdb if needed
80- -- end
74+ -- Uncomment code if you use surrealdb
75+ -- if (db_config ~= nil and db_config["engine"] == "surrealdb") then
76+ -- Surreal.refresh_token(db_config[BeansEnv]) -- reconnect to surrealdb if needed
77+ -- end
8178
82- DefineRoute (GetPath (), GetMethod ())
79+ DefineRoute (GetPath (), GetMethod ())
8380
84- HandleRequest ()
85- -- Uncomment if you use redis
86- -- unix.close(Redis.network.socket)
81+ HandleRequest ()
82+ -- Uncomment if you use redis
83+ -- unix.close(Redis.network.socket)
8784end
8885
8986function SetDevice ()
90- local user_agent = GetHeader (" User-Agent" )
91- Params .request = { variant = " " }
92- local preg = assert (re .compile (" iPhone" ))
93- if preg :search (user_agent ) then
94- Params .request .variant = " iphone"
95- end
87+ local user_agent = GetHeader (" User-Agent" )
88+ Params .request = { variant = " " }
89+ local preg = assert (re .compile (" iPhone" ))
90+ if preg :search (user_agent ) then
91+ Params .request .variant = " iphone"
92+ end
9693end
0 commit comments