@@ -8,6 +8,7 @@ Surreal = {}
88
99function LoadViewsRecursively (path )
1010 local dir = unix .opendir (path )
11+ assert (dir ~= nil , " Error while opening path " .. path )
1112
1213 while true do
1314 local file , kind = dir :read ()
@@ -26,8 +27,6 @@ function LoadViewsRecursively(path)
2627
2728 end
2829 dir :close ()
29-
30- return layouts
3130end
3231
3332function Page (view , layout , bindVarsView , bindVarsLayout )
@@ -263,17 +262,17 @@ function HandleRequest()
263262
264263
265264 if GetPath () == " /" then
266- path = {
265+ local default_routes = {
267266 [" GET" ] = " /index" ,
268267 [" POST" ] = " /create" ,
269268 [" PUT" ] = " /update" ,
270269 [" PATCH" ] = " /update" ,
271270 [" DELETE" ] = " /delete"
272271 }
273- path = path [GetMethod ()]
272+ path = default_routes [GetMethod ()]
274273 end
275274
276- local aql_page = false
275+ local aql_page = nil
277276 if not string.match (path , " %." ) then -- check only if there is no extension
278277 aql_page = LoadAsset (" aqlpages/" .. path .. " .aql" )
279278 end
323322function WriteJSON (object )
324323 SetHeader (" Content-Type" , " application/json; charset=utf-8" )
325324 local json = EncodeJson (object )
325+ assert (json ~= nil , " Object is not serializable" )
326+
326327 local etag = EncodeBase64 (Md5 (json ))
327328
328329 if etag == GetHeader (" If-None-Match" ) then
391392
392393function LoadPublicAssetsRecursively (path )
393394 local dir = unix .opendir (path )
395+ assert (dir ~= nil , " Error while opening path " .. path )
396+
394397 while true do
395398 local file , kind = dir :read ()
396399 if file == nil then break end
@@ -445,6 +448,7 @@ function LoadCronsJobs(path)
445448 if os.date (" %S" ) == " 00" then -- run every minute
446449 path = path or " app/cronjobs"
447450 local dir = unix .opendir (path )
451+ assert (dir ~= nil , " Error while opening path " .. path )
448452
449453 while true do
450454 local file , kind = dir :read ()
0 commit comments