73 lines
1.3 KiB
Lua
73 lines
1.3 KiB
Lua
local omg = require("omg")
|
|
omg()
|
|
|
|
-- function sleep(a)
|
|
-- local sec = tonumber(os.clock() + a);
|
|
-- while (os.clock() < sec) do
|
|
-- end
|
|
-- end
|
|
|
|
--[[
|
|
Admin Section
|
|
]]
|
|
local admin = create_app()
|
|
admin:get("/", function(req, res)
|
|
res.status = 200
|
|
res.body = "Admin"
|
|
return res
|
|
end)
|
|
|
|
--[[
|
|
Main App
|
|
]]
|
|
local app = create_app()
|
|
app:get("/foo/:number", function(req, res)
|
|
res.body = { data = req.params.number }
|
|
return res
|
|
end)
|
|
app:get("/:one/:two/:three/:four/:five", function(req, res)
|
|
print(req.params.five)
|
|
res.body = { data = req.params.one }
|
|
return res
|
|
end)
|
|
app:get("/bar", function(req, res)
|
|
res.status = 200
|
|
res.body = "Hello, World!"
|
|
sleep(3)
|
|
return res
|
|
end)
|
|
app:post("/submit", function(req, res)
|
|
print(req.body)
|
|
return res
|
|
end)
|
|
|
|
--[[ wip ]]
|
|
-- app:ws("/ws", function(ws)
|
|
-- ws:on("message", function(msg)
|
|
-- print(msg)
|
|
-- end)
|
|
-- return ws
|
|
-- end)
|
|
-- app:ws("/ws", {
|
|
-- on_connect = function(ws)
|
|
-- print("lua connect cb")
|
|
-- table.insert(ws_clients, ws)
|
|
-- end,
|
|
-- on_message = function(ws, message)
|
|
-- print("lua message cb")
|
|
-- end,
|
|
-- })
|
|
|
|
app:use("/admin", admin)
|
|
|
|
-- Run App
|
|
app:run(3000)
|
|
|
|
local otherapp = create_app()
|
|
otherapp:get("/", function(req, res)
|
|
res.status = 200
|
|
res.body = "Admin"
|
|
return res
|
|
end)
|
|
otherapp:run(3001)
|