server.headers

  • Type: Record<string, string | string[]>
  • Default: undefined

Adds headers to all responses sent from Rsbuild server. This configuration directly leverages Node.js response.setHeader() method under the hood.

If the header already exists in the to-be-sent headers, its value will be overwritten.

TIP

To set CORS headers like Access-Control-Allow-Origin, use server.cors option.

If both server.headers and server.cors are used, server.headers will override server.cors.

Usage

The server.headers option accepts an object where:

  • Keys are header names (case-insensitive)
  • Values are either a string or an array of strings
rsbuild.config.ts
export default {
  server: {
    headers: {
      'X-Custom-Foo': 'bar',
    },
  },
};

Multiple values

Use an array of strings to send multiple headers with the same name.

rsbuild.config.ts
export default {
  server: {
    headers: {
      // Multiple Set-Cookie headers
      'Set-Cookie': ['type=ninja', 'language=javascript'],
    },
  },
};