bizwiz3/nova
v0.5.0 ·
A filesystem-based web framework for Luau runtimes, with out-of-the-box support for Lune and Zune.
Table of Contents
Installation & Usage
Installation
Install Nova via the Pesde package manager:
pesde add bizwiz3/nova
pesde install
Usage
Manual Setup
- Create a
src/directory in your project root. - Create an entry file (e.g.,
index.luau) insidesrc/with the following code:
local Nova = require("@path/to/nova")
local app = Nova.new(8080)
app:listen() -- To run the server
- Create an
app/directory insidesrc/. This directory will house your routes. - To create a route, add a
route.luaufile inside a directory withinapp/. The directory name becomes the base route.
For example, to create a route at /, create src/app/route.luau:
local Nova = require("@path/to/nova")
local App = {}
function App.Get()
return Nova.response.json({ msg = "Hello, Nova" })
end
return App
The module must export properties named after HTTP methods: Get, Post, Put, Patch, and Delete. You can define them as functions:
local App = {}
App.Get = function()
return Nova.response.json({ msg = "Hello, Nova" })
end
return App
Core Features
- Filesystem Routing: Routes are automatically mapped to the directory structure of the
appfolder. - Pattern Matching: Native support for dynamic segments using
[params]syntax. - Middleware Pipeline: Functional middleware chaining for global and route-specific logic.
- Unified Response Utility: Standardized handling for JSON and HTML content types.
- Environment Management: Automatic
.envloading and process injection. - Integrated Logger: Colored terminal output for request monitoring and debugging.
Routing Conventions
Nova follows a predictable mapping from the filesystem to the URL path:
| Path | Filesystem Map |
|---|---|
| / | src/app/route.luau |
| /users | src/app/users/route.luau |
| /posts/ | src/app/posts/[id]/route.luau |
Middleware Chaining
Utilize the chain helper to apply logic sequentially before a request reaches the final handler:
-- route.luau
local Nova = require("@path/to/nova")
local function validate(req, next)
if not req.headers["x-api-key"] then
return Nova.response.json({ error = "Forbidden" }, { status = 403 })
end
next()
end
Route.Get = Nova.chain({ validate }, function(req)
return Nova.response.json({ data = "Authorized access" })
end)
More info about middlewares soon.