Views
Web rendering is optional in the starter. Netpress can render React or Vue components on the server, or skip web rendering entirely when the app is API-only.
Quick Example
// app/Http/Controllers/HomeController.js
import HomePage from "../../../resources/views/pages/HomePage.jsx";
class HomeController {
index(_req, res) {
return res.render(HomePage, {
appName: "Netpress",
title: "Netpress Starter Kit",
message: "Build APIs, pages, and mail in one simple Node.js app.",
});
}
}
export default new HomeController();
The View Engine Switch
config/view.js controls whether web routes are mounted and which renderer to use:
export default {
engine: "react",
};
Valid values:
"react""vue"null
When the value is null, RouteServiceProvider does not mount routes/web.js.
What setup:rendering Writes
Running:
npm run artisan -- setup:rendering
updates the starter web files:
config/view.jsroutes/web.jsapp/Http/Controllers/HomeController.jsresources/views/layouts/resources/views/pages/
That command is the normal way to enable or change the starter web renderer.
Rendering Modes
There are two view paths:
Component Rendering
When you pass a component to res.render(...) or view(...), Netpress uses the registered renderer from AppServiceProvider, which calls renderView(...) with the configured engine.
String Templates
When you pass a string like "dashboard" to res.render(...) or view("dashboard", props), Netpress delegates to Express res.render(...) like a normal Express app.
Shared View State
The web route stack and the shared view middleware make these available to server-rendered pages:
errors, anErrorBagold(field, fallback)flash, including flashed status messagescsrfTokenafter the controller callsreq.csrfToken()auth.user,auth.guard,auth.check, andauth.guestAuth.user(),Auth.check(), andAuth.guest()can(), which resolves through core authorization
That is what powers form redirects like:
return redirect("/register")
.withErrors({ email: ["Required"] })
.withInput(req.body);
For auth pages and other server-rendered forms, redirects can also flash a status message:
return redirect("/login")
.withSuccess("Your password has been reset.");
When a page contains a form, request the CSRF token before rendering and post it back as _token:
class SessionsController {
create(req, res) {
req.csrfToken();
return res.render(LoginPage);
}
}
export default function LoginPage({ csrfToken = "" }) {
return (
<form method="post" action="/login">
<input type="hidden" name="_token" value={csrfToken} />
<input type="email" name="email" />
<input type="password" name="password" />
</form>
);
}
The starter auth pages already include this wiring.
These helpers are part of the web stack. API routes do not receive session, flash, or CSRF view state.
Publishing Starter Auth Views
The starter ships default auth pages for the web guard. To republish them for a different renderer or UI stack:
npm run artisan -- setup:auth
npm run artisan -- setup:auth --web react --ui tailwind
npm run artisan -- setup:auth --web vue --ui bootstrap
That command writes:
resources/views/layouts/AuthLayout.*resources/views/pages/auth/*
Use it when you switch between React and Vue, or when you want the starter auth pages to follow a Tailwind-style or Bootstrap-style surface.
Folder Layout
resources/views/pages/for page componentsresources/views/layouts/for layouts and shared chrome
Use resources/mails/ for email templates instead. Web and mail rendering are separate systems even when they use the same engine family.