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:
"/path"— path to the static directory relative to the process working directory.{ path: "/path", prefix: "/prefix" }— directory path + URL prefix.- 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' }]
},
...
];