1.0.0 • Published 6 months ago

jcc-mvc-inertia v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Inertia Middleware for jcc-express-mvc

Installation

npm install jcc-mvc-inertia

Usage

This middleware integrates Inertia.js with your Express-based framework, allowing seamless handling of Inertia requests.

Register Middleware in Kernel

To globally register the middleware, add it to your app/Http/kernel.ts file:

import { inertia } from "@your-scope/inertia-middleware";

export class Kernel {


  protected middleware = [
    inertia({ rootView: "index" }),
  ];

}

Using Inertia in a Controller

If you prefer to use Inertia middleware only for specific routes:

import { Route } from "jcc-express-mvc/Route";

Route.get("/", (req, res) => res.inertia("Dashboard", { user: req.user }));

Handling Inertia Requests

  • If the request contains X-Inertia header, JSON response is returned.
  • Otherwise, the root view is rendered with Inertia data.