app-def.ts

The app-def.ts file is the central configuration file that defines the shape and behavior of your Corract application. It specifies all routes, their layouts, their middleware, and associated API endpoints. Corract uses this file to generate the entire file structure under as well as to power client-side routing and server-side behavior. (see: app-client.tsx)

This is the heart of the “super-opinionated” approach Corract takes: instead of you creating files and wiring up routing manually, Corract generates what it needs based on app-def.ts.

Structure

The pages object defines the routes your app supports, and how each route is composed. Each route entry supports:

  • key – The URL path for the route, e.g. /home.
  • layout – The layout component that wraps this route, e.g. HomeLayout.
  • middleware – An optional server-side middleware function that runs before rendering the page.
export const pages = {
  '/': {
    middleware: [globalMiddleware],
    layouts: [Navbar],
  },
  '/profile': {
    middleware: [globalMiddleware],
    layouts: [Navbar, Profile],
  },
  '/profile/demo': {
    middleware: [globalMiddleware],
    layouts: [],
  },
  '/profile/:id': {
    middleware: [globalMiddleware],
    layouts: [Profile],
  },
  '/tasks': {
    middleware: [globalMiddleware],
    layouts: [Navbar],
  },
  ...appDefDocs,
} as const