Features
Routing
Netpress routing is built on Express routers plus a small wrapper that adds Laravel-style route groups and smart-response dispatch.
Quick Example
// routes/api.js
import { Router } from "@admicaa/netpress";
import authRoutes from "./auth.js";
import userRoutes from "./users.js";
import { db } from "../app/Providers/DatabaseServiceProvider.js";
import appConfig from "../config/app.js";
const router = Router();
router.get("/health", () => ({
status: "ok",
db: db.type,
env: appConfig.env,
}));
router.group("/auth", (auth) => {
auth.use("/", authRoutes);
});
router.group("/users", (users) => {
users.use("/", userRoutes);
});
export default router;
Where Routes Mount
RouteServiceProvider mounts:
routes/web.jsat/whenconfig/view.jsenables a web engineroutes/api.jsunder/api/v1
That means the example "/health" route above is served at /api/v1/health.
Router.group()
Router.group() accepts:
- a prefix and a callback
- one or more middleware functions and a callback
- a prefix, one or more middleware functions, and a callback
Examples:
router.group("/api", (api) => {
api.get("/health", () => ({ ok: true }));
});
router.group(authMiddleware, (protectedRoutes) => {
protectedRoutes.get("/me", (req) => req.user);
});
router.group("/admin", [authMiddleware, requireRole("admin")], (admin) => {
admin.get("/users", UserController.index);
});
Nested groups preserve parent params:
router.group("/users/:userId", (users) => {
users.group("/posts", (posts) => {
posts.get("/:postId", (req) => req.params);
});
});
Smart Response Dispatch
Only the last non-error handler in a route is auto-dispatched. Earlier middleware stays untouched.
A terminal handler can return:
| Return value | Result |
|---|---|
| plain object or array | JSON |
view(componentOrName, props) | HTML |
json(data, status?) | JSON with explicit status |
redirect(url, status?) | redirect |
| string | text/plain |
Buffer | raw body |
number or boolean | JSON |
null or undefined | 204 No Content |
res | treated as already handled |
Manual res.send, res.json, res.render, res.redirect, res.end, res.sendFile, res.download, and res.sendStatus continue to work normally.
Route Listing
The starter CLI can print every mounted route:
npm run artisan -- route:list
That is especially useful after adding nested groups or when web routes are conditionally mounted through config/view.js.