> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Interface: Server

The Server option changes the behavior of dev-server.

## Properties

### base?

> `optional` **base?**: `string`

Configure the base path of the server.

#### Default Value

`'/'`

#### Remarks

Users can access lynx bundle through `http://<host>:<port>/main.lynx.bundle` by default.

If you want to access lynx bundle through `http://<host>:<port>/foo/main.lynx.bundle`, you can change `server.base` to `/foo`

you can refer to [server.base](https://rsbuild.rs/config/server/base) for more information.

#### Example

```js
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
  server: {
    base: '/dist'
  },
})
```

***

### compress?

> `optional` **compress?**: `boolean` | `CompressOptions`

Configure whether to enable [gzip compression](https://developer.mozilla.org/en-US/docs/Glossary/gzip_compression) for static assets served by the dev server or preview server.

#### Default Value

```ts
true
```

#### Remarks

See [Rsbuild - server.compress](https://rsbuild.rs/config/server/compress) for details.

#### Examples

To disable the gzip compression, set compress to false:

```js
export default {
  server: {
    compress: false,
  },
}
```

Compress if it starts with /foo

```js
export default {
  server: {
    compress: {
      filter: (req) => {
        if (req.url?.includes('/foo')) {
          return false;
        }
        return true;
      },
    },
  },
}
```

set level of zlib compression

```js
export default {
  server: {
    compress: {
      level: 6,
    },
  },
}
```

***

### cors?

> `optional` **cors?**: `boolean` | `CorsOptions`

Configure CORS for the dev server or preview server.

#### Default Value

```ts
Uses Rsbuild's default CORS options.
```

#### Remarks

- Set to an object to enable CORS with the specified options.

- Set to `true` to enable CORS with the default options (allows all origins, not recommended).

- Set to `false` to disable CORS.

See [Rsbuild - server.cors](https://rsbuild.rs/config/server/cors) for details.

#### Example

```js
export default {
  server: {
    cors: {
      origin: 'https://example.com',
    },
  },
}
```

***

### headers?

> `optional` **headers?**: `Record`\<`string`, `string` | `string`\[]>

Adds headers to all responses.

#### Default Value

```ts
undefined
```

#### Example

```js
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
  server: {
    headers: {
      'Access-Control-Allow-Origin': '**',
    },
  },
})
```

***

### host?

> `optional` **host?**: `string`

**`Lynx Default Changed`**

Specify the host that the Rspeedy Server listens to.

#### Default Value

```ts
"0.0.0.0"
```

#### Remarks

During `rspeedy dev`, if `server.host` is unset, the dev plugin keeps the server bound to the IPv4 wildcard address while resolving dev-server-related URLs and client host settings with a detected non-loopback IPv4 address, such as `192.168.1.50`. If no eligible IPv4 address exists, it binds to the IPv6 wildcard address and uses a detected IPv6 address for URLs. It falls back to an IPv4 loopback URL when no non-loopback IP is available. If you have multiple network interfaces, set `server.host` explicitly to choose the desired address.

#### Example

Set the host to a custom value:

```js
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
  server: {
    host: "192.168.1.50",
  },
})
```

***

### port?

> `optional` **port?**: `number`

Specify the port that the Rspeedy Server listens to.

#### Default Value

Rsbuild defaults this option to `3000`.

#### Remarks

By default, the server automatically increments the port number when the configured port is occupied.

#### Example

Set the port to a custom value:

```js
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
  server: {
    port: 3470,
  },
})
```

***

### proxy?

> `optional` **proxy?**: `ProxyConfig`

Configure proxy rules for the dev server or preview server to proxy requests to the specified service.

#### Default Value

```ts
undefined
```

#### Example

```js
export default {
  server: {
    proxy: {
      // http://localhost:3000/api -> http://localhost:3000/api
      // http://localhost:3000/api/foo -> http://localhost:3000/api/foo
      '/api': 'http://localhost:3000',
    },
  },
}
```

***

### strictPort?

> `optional` **strictPort?**: `boolean`

When a port is occupied, Rspeedy will automatically increment the port number until an available port is found.

#### Default Value

```ts
false
```

#### Remarks

By default, strict port mode is disabled. Set strictPort to true and Rspeedy will throw an exception when the port is occupied.
