Mock config server
Mocking requests

Static Files

Static file serving configuration

Mock Config Server can serve static files. You can serve HTML, JSON, images, styles, and any other files.

Usage

Set staticPath in the server config. This tells the server to mount static files.

Supported formats:

  1. "/path" — path to the static directory relative to the process working directory.
  2. { path: "/path", prefix: "/prefix" } — directory path + URL prefix.
  3. An array of strings and/or objects for multiple sources.

You can also pass staticPath to the CLI via --staticPath (or -s).

Examples

Minimal setup:

import type { MockServerConfig } from 'mock-config-server';

export const mockServerConfig: MockServerConfig = [
  {
    staticPath: '/images'
  },
  ...
];

Static files with a prefix:

import type { MockServerConfig } from 'mock-config-server';

export const mockServerConfig: MockServerConfig = [
  {
    staticPath: {
      path: '/images',
      prefix: '/files'
    }
  },
  ...
];

Multiple sources:

import type { MockServerConfig } from 'mock-config-server';

export const mockServerConfig: MockServerConfig = [
  {
    staticPath: ['/images', { path: '/assets', prefix: '/static' }]
  },
  ...
];

On this page