No description
- Lua 87.8%
- CSS 6.1%
- HTML 6.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| handlers | ||
| static | ||
| views | ||
| handlers.lua | ||
| README.md | ||
| server.lua | ||
minilua-mvc
A mini MVC framework in pure Lua, served by Ncat's --lua-exec. Ships with a
WireGuard control panel as the example app. No dependencies beyond ncat.
Requirements
- ncat (from the nmap package)
- wireguard-tools and root privileges (for the panel example)
Run
sudo ncat -l -k --lua-exec server.lua 8080
Then open http://localhost:8080/ — green button brings wg0 up, red brings
it down, and the page shows the current wg status.
Layout
server.lua— the framework: HTTP parsing, routing, templates, static files. Never edit this to add a page.handlers.lua— route index;dofiles the files inhandlers/.handlers/*.lua— routes registered into the globalroutestable. Key is"METHOD /path"(:namecaptures a path segment intorequest.params["name"]); the handler gets a request table (method,path,params,query,form) and returns the response body.redirect("/path")sends a 302.views/*.html— templates:{{name}}escaped,{{{name}}}raw,{{>file.html}}include,{{#name}}...{{else}}...{{/name}}if-truthy,{{^name}}...{{/name}}if-falsy.static/— served as-is under/static/....
Adding a page
-
Create
handlers/foo.lua:routes["GET /foo"] = function(request) return render("foo.html", {["title"] = "Foo"}) end -
Add
dofile("handlers/foo.lua")tohandlers.lua. -
Create
views/foo.html.
Security notes
- Only
/static/...is served from disk; path traversal is rejected. - Never interpolate request data into
io.popen()command strings.