55 lines
998 B
Lua
55 lines
998 B
Lua
print([[
|
|
|
|
===============================================================================
|
|
examples:
|
|
===============================================================================
|
|
curl localhost:3000
|
|
=> Not Found
|
|
|
|
curl localhost:3000/42
|
|
=> {"data":"42"}
|
|
|
|
curl -d "test=hello&test2=world" localhost:3000/submit
|
|
=> hello world
|
|
|
|
curl localhost:3000/admin
|
|
=> Admin
|
|
|
|
curl localhost:3001
|
|
=> Admin
|
|
===============================================================================
|
|
]])
|
|
|
|
--[[
|
|
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.json = { data = req.params.segment }
|
|
return res
|
|
end)
|
|
|
|
app:post("/submit", function(req, res)
|
|
res.body = req.form.test .. " " .. req.form.test2
|
|
return res
|
|
end)
|
|
|
|
-- Bind Admin Section
|
|
app:use("/admin", admin)
|
|
-- Run App
|
|
app:run(3000)
|
|
-- Run Admin Section standalone
|
|
admin:run(3001)
|