This commit is contained in:
parent
a6d8f3b86b
commit
c091528f9f
8
examples/hello.lua
Normal file
8
examples/hello.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
local app = create_app()
|
||||||
|
|
||||||
|
app:get("/", function(req, res)
|
||||||
|
res.body = "Hello, World!"
|
||||||
|
return res
|
||||||
|
end)
|
||||||
|
|
||||||
|
app:run(3000)
|
||||||
9
examples/require.lua
Normal file
9
examples/require.lua
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
local lib = require("require_lib")
|
||||||
|
|
||||||
|
local app = create_app()
|
||||||
|
|
||||||
|
app:get("/", function(req,res)
|
||||||
|
return lib.identity(res)
|
||||||
|
end)
|
||||||
|
|
||||||
|
app:run(3000)
|
||||||
7
examples/require_lib.lua
Normal file
7
examples/require_lib.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.identity(...)
|
||||||
|
return ...
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
32
examples/server.lua
Normal file
32
examples/server.lua
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
--[[
|
||||||
|
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("/:segment", function(req, res)
|
||||||
|
res.body = { data = req.params.segment }
|
||||||
|
return res
|
||||||
|
end)
|
||||||
|
|
||||||
|
app:post("/submit", function(req, res)
|
||||||
|
print(req.body)
|
||||||
|
return res
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Bind Admin Section
|
||||||
|
app:use("/admin", admin)
|
||||||
|
-- Run App
|
||||||
|
app:run(3000)
|
||||||
|
-- Run Admin Section standalone
|
||||||
|
admin:run(3001)
|
||||||
72
server.lua
72
server.lua
@ -1,72 +0,0 @@
|
|||||||
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)
|
|
||||||
Loading…
Reference in New Issue
Block a user