1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00

minor fix on apigateway handling

This commit is contained in:
DanyLE 2022-08-30 16:31:08 +02:00
parent 4016a0abef
commit 5b8acf2d87

View File

@ -140,11 +140,13 @@ function SystemController:apigateway(...)
r, e = load(data.code) r, e = load(data.code)
if r then if r then
local status, result = pcall(r) local status, result = pcall(r)
if result then
if (status) then if (status) then
echo(JSON.encode(result)) echo(JSON.encode(result))
else else
echo(result) echo(result)
end end
end
else else
echo(e) echo(e)
end end
@ -169,12 +171,13 @@ function SystemController:apigateway(...)
end end
if (is_auth()) then if (is_auth()) then
local pid = ulib.fork() local pid = ulib.fork()--std.pfork(HTTP_REQUEST.id)
if (pid == -1) then if (pid == -1) then
echo("{'error':'Cannot create process'}") echo("{'error':'Cannot create process'}")
elseif pid > 0 then -- parent elseif pid > 0 then -- parent
-- wait for the child exit or websocket exit -- wait for the child exit or websocket exit
ulib.waitpid(pid, 0) ulib.waitpid(pid, 0)
--ulib.kill(pid)
print("Parent exit") print("Parent exit")
else -- child else -- child
if use_ws then if use_ws then
@ -189,7 +192,7 @@ function SystemController:apigateway(...)
std.ws.close(1012) std.ws.close(1012)
elseif header.opcode == std.ws.CLOSE then elseif header.opcode == std.ws.CLOSE then
print("Connection closed") print("Connection closed")
std.ws.close(1000) -- std.ws.close(1000)
elseif header.opcode == std.ws.TEXT then elseif header.opcode == std.ws.TEXT then
-- read the file -- read the file
local data = std.ws.read(header) local data = std.ws.read(header)
@ -198,7 +201,7 @@ function SystemController:apigateway(...)
exec_with_user_priv(data) exec_with_user_priv(data)
std.ws.close(1011) std.ws.close(1011)
else else
echo("Error: Invalid request") print("Error: Invalid request")
std.ws.close(1011) std.ws.close(1011)
end end
end end