JCC Express

Response

Introduction

Every HTTP handler receives an Express Response object. JCC Express MVC types it as AppResponse (jcc-express-mvc/lib/Interface): it is the same instance passed as res in route closures and in { req, res, next } / httpContext patterns.

Early in the global middleware stack, HttpResponse (jcc-express-mvc/lib/Response/index.ts) wraps each pair (req, res) and attaches res.with and res.redirectBack. If you register inertia(...) in the HTTP kernel, the Inertia middleware adds res.inertia and res.inertiaRedirect.

Use the global response() helper to resolve the current AppResponse from the container (only during an HTTP request, after per-request binding).

Types: import type { Response } from "jcc-express-mvc" as the AppResponse alias (export type { AppResponse as Response }).


When extensions are available

with and redirectBack are wired when HttpResponse is constructed (same phase as HttpRequest helpers). inertia and inertiaRedirect exist only after the inertia({ rootView, ssr, ... }) middleware runs, which must be in your kernel’s middlewares array if you use Inertia.


Flash and redirects

  • res.with(message, type?) — Flashes a message (default flash type success). Uses jccSession.flash when available, otherwise req.flash. Returns res for chaining. See Session.md for how session and flash fit together.
  • res.redirectBack() — Redirects with status 303 to the Referer header, or the first entry in the framework’s tracked URL list, or / as a fallback.

Globals redirect(url, status?) (default status 303) and back(url?) (explicit URL or redirectBack) call through the bound response.


Inertia

Requires inertia(...) in the kernel (see Getting-Started/Frontend.md for rootView, ssr, version, shared props).

  • await res.inertia(component, props?, option?) — For XHR Inertia visits (X-Inertia header), responds with JSON (page object, version checks, partial reloads via X-Inertia-Partial-Data). For a full load, renders rootView with inertia, ssrHead, ssrBody when SSR is enabled and the SSR server is reachable.
  • res.inertiaRedirect(url) — If the request is Inertia, sets X-Inertia-Location and responds with 409; otherwise res.redirect(303, url).

Global inertia(component, props?, option?) delegates to res.inertia.


Server-rendered views

Use Express’s res.render(view, locals?, callback?) with your configured view engine (Blade-style templates, etc.). The global view(name, options?, callback?) helper resolves response and calls render. For paths, configuration, and Route.view, see Views.md; for the Blade engine itself, see JCC-Blade.md (same folder).

res.locals is populated by the framework where relevant—for example validation errors and old input from HttpRequest, and _token for CSRF when csrf() is active (see Request.md and CSRF-protection.md).


Standard Express behavior

Everything from express.Response still applies, including:

  • res.status(code), res.json(body), res.send(body), res.end()
  • res.redirect(statusOrUrl, url?) (Express overload rules)
  • res.set / res.get, res.cookie / res.clearCookie
  • res.headersSent — useful before calling redirect or json twice

If your route handler returns a non-undefined value and the response is not yet sent, the route wrapper may serialize it as JSON (see router registration in RouteBuilder).