Improved error handling, although some bugs still persist
This commit is contained in:
parent
76c2895f04
commit
7bd9b266be
@ -23,11 +23,11 @@ return function (port)
|
|||||||
else
|
else
|
||||||
local fileExists = file.open(uri.file, "r")
|
local fileExists = file.open(uri.file, "r")
|
||||||
file.close()
|
file.close()
|
||||||
|
collectgarbage()
|
||||||
if not fileExists then
|
if not fileExists then
|
||||||
uri.args['code'] = 404
|
uri.args['code'] = 404
|
||||||
fileServeFunction = dofile("httpserver-error.lc")
|
fileServeFunction = dofile("httpserver-error.lc")
|
||||||
elseif uri.isScript then
|
elseif uri.isScript then
|
||||||
collectgarbage()
|
|
||||||
fileServeFunction = dofile(uri.file)
|
fileServeFunction = dofile(uri.file)
|
||||||
else
|
else
|
||||||
uri.args['file'] = uri.file
|
uri.args['file'] = uri.file
|
||||||
@ -45,11 +45,12 @@ return function (port)
|
|||||||
-- parse payload and decide what to serve.
|
-- parse payload and decide what to serve.
|
||||||
local req = dofile("httpserver-request.lc")(payload)
|
local req = dofile("httpserver-request.lc")(payload)
|
||||||
print("Requested URI: " .. req.request)
|
print("Requested URI: " .. req.request)
|
||||||
if req.methodIsValid then
|
if req.methodIsValid and req.method == "GET" then
|
||||||
if req.method == "GET" then onGet(connection, req.uri)
|
onGet(connection, req.uri)
|
||||||
else dofile("httpserver-static.lc")(conection, {code=501}) end
|
|
||||||
else
|
else
|
||||||
dofile("httpserver-static.lc")(conection, {code=400})
|
local args = {}
|
||||||
|
if req.methodIsValid then args['code'] = 501 else args['code'] = 400 end
|
||||||
|
dofile("httpserver-error.lc")(connection, args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,9 +74,9 @@ return function (port)
|
|||||||
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
if wifi.sta.getip() then print("nodemcu-httpserver running at http://" .. wifi.sta.getip() .. ":" .. port)
|
local ip = nil
|
||||||
else print("nodemcu-httpserver running at http://" .. wifi.ap.getip() .. ":" .. port)
|
if wifi.sta.getip() then ip = wifi.sta.getip() else ip = wifi.ap.getip() end
|
||||||
end
|
print("nodemcu-httpserver running at http://" .. ip .. ":" .. port)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user