API Reference

JopiRouteConfig

Documentation for the JopiRouteConfig class.

JopiRouteConfig

The JopiRouteConfig class provides a fluent API to configure specific routes programmatically. It allows you to attach middlewares, enforce role-based access control, and manage menu integration for different HTTP methods on the same route.

You typically access an instance of this class via the linker or route definition files.

Structure

The class exposes configuration objects for each HTTP method:

  • onGET: Configuration for GET requests.
  • onPOST: Configuration for POST requests.
  • onPUT, onDELETE, onPATCH, onHEAD, onOPTIONS: Configurations for other standard methods.
  • onALL: Configuration applied to all methods.
  • onPage: specialized configuration for GET requests that serve React pages.

Core Configuration Methods

These methods are available on onGET, onPOST, etc.

add_middleware(middleware, priority)

Adds a middleware to the specific route and method. It will execute before the request handler.

add_postMiddleware(middleware, priority)

Adds a post-middleware that executes after the request handler has generated a response.

add_requiredRole(...roles)

Enforces role-based access control. only users with one of the specified roles will be allowed to access the route.

Page-Specific Configuration (onPage)

These methods are available only on the onPage property.

cache_disableAutomaticCache()

Disables the automatic cache engine for this page. The page will be re-rendered on every request.

cache_afterGetFromCache(handler)

Hooks into the cache lifecycle. Called after a response is retrieved from the cache, allowing you to modify it before sending it to the client.

cache_beforeAddToCache(handler)

Hooks into the cache lifecycle. Called before a response is added to the cache. Returning undefined prevents caching.

cache_beforeCheckingCache(handler)

Called before checking the cache. Useful for custom security checks or early exits that bypass the cache completely.

Registers the route as a menu entry in a specific menu.

  • menuName: The identifier of the menu (e.g., "layout.top").
  • keys: Translation keys or title strings for the menu label.
  • menuItem: Additional properties like icon (icon) and sort priority (priority).

Shortcuts

  • menu_addToLeftMenu(keys, menuItem)
  • menu_addToRightMenu(keys, menuItem)
  • menu_addToTopMenu(keys, menuItem)

These methods return an object that allows further customization of the menu entry's visibility based on roles:

  • requireRoles(...roles)
  • ignoreRoles()