For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/packages/rspeedy/interfaces/Server.md.
Lynx
  • English
  • 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 for more information.

    Example

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

    compress?

    optional compress?: boolean | CompressOptions

    Configure whether to enable gzip compression for static assets served by the dev server or preview server.

    Default Value

    true

    Remarks

    See Rsbuild - server.compress for details.

    Examples

    To disable the gzip compression, set compress to false:

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

    Compress if it starts with /foo

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

    set level of zlib compression

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

    cors?

    optional cors?: boolean | CorsOptions

    Configure CORS for the dev server or preview server.

    Default Value

    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 for details.

    Example

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

    headers?

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

    Adds headers to all responses.

    Default Value

    undefined

    Example

    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

    "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:

    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:

    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

    undefined

    Example

    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

    false

    Remarks

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

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.