Skip to content

Latest commit

 

History

History
212 lines (145 loc) · 3.33 KB

File metadata and controls

212 lines (145 loc) · 3.33 KB

Configuration

StatikAPI works without a config file, but you can customize behavior with statikapi.config.js.

Basic example:

export default {
  srcDir: 'src-api',
  outDir: 'api-out',
};

Supported top-level config fields

srcDir

  • type: string
  • default: "src-api"

This is the directory that contains route modules.

Supported route file extensions in the regular CLI path:

  • .js
  • .mjs
  • .cjs
  • .ts
  • .tsx

outDir

  • type: string
  • default: "api-out"

This is where the regular CLI writes generated JSON.

It also writes:

  • .statikapi/manifest.json

inside the output directory.

listIndex

  • type: boolean | { enabled?: boolean, pick?: string[] }
  • default: disabled

listIndex controls whether dynamic and catch-all routes also emit a parent collection route.

Examples:

export default {
  listIndex: true,
};
export default {
  listIndex: {
    enabled: true,
    pick: ['id', 'title'],
  },
};

Effects:

  • dynamic route /posts/[id]
    • item routes: /posts/1, /posts/2
    • collection route: /posts
  • catch-all route /docs/[...slug]
    • item routes: /docs/guide, /docs/api/intro
    • collection route: /docs

When pick is present:

  • each collection item must be a plain object
  • only the listed keys are included in the parent collection route

Route-level config

Routes can also export:

export const config = {
  listIndex: true,
};

or:

export const config = {
  listIndex: {
    enabled: true,
    pick: ['slug'],
  },
};

Route-level config.listIndex overrides the project default for that route.

In Cloudflare projects, route modules may also export:

export const config = {
  cloudflare: {
    public: false,
    webhook: true,
  },
};

See Cloudflare Worker + Static Assets Adapter.


Validation rules

srcDir and outDir:

  • must be non-empty strings
  • must be relative paths
  • must not traverse outside the project
  • must not be the same directory

listIndex:

  • true means enabled with defaults
  • false means disabled
  • pick must be an array of non-empty strings

If config validation fails, the CLI exits with a config error before building.


CLI overrides

The regular CLI can override config per invocation.

Build

pnpm statikapi build --srcDir api --outDir public/api --listIndex=true

Dev

pnpm statikapi dev --srcDir api --outDir public/api --port 8788

Supported override flags include:

  • --srcDir
  • --outDir
  • --listIndex
  • --listIndexPick

Dev-server notes

statikapi dev:

  • serves the preview UI at /_ui/
  • updates .statikapi/manifest.json
  • watches route files for changes
  • deletes stale outputs when routes disappear

Advanced environment overrides:

  • STATIKAPI_UI_DIR
    • custom prebuilt UI directory
  • STATIKAPI_FORCE_DEV=1
    • force long-running dev behavior in non-TTY environments

Common patterns

Custom directories

export default {
  srcDir: 'api',
  outDir: 'public/api',
};

Global collection indexes

export default {
  listIndex: {
    enabled: true,
    pick: ['id', 'title'],
  },
};

Monorepo package-local config

Put statikapi.config.js in the package root where you run the CLI.

The CLI resolves config relative to the current working directory.