Skip to main content
Version: 3.0.0

Configuring the server

Setting the port

port: number;

Securing the connection

  • Set this if you want to secure the connection

    https?: { ... }
    • The path to the certificate file. Supports: .pem
        pathToCert: string;
    • The path to the certificate key file. Supports: .pem
        pathToKey: string;
    • The password which the certificate is encrypted with.
        passphrase?: string;
    • Whether to allow self-signed certificates.
        allowSelfSigned?: boolean;

Verbose logging

verbose?: boolean;

Logger

  • You can override the server's default Logger system by giving this property an ILogger interface.
  • If you set it true, the default logging script will be used.
logger?: boolean | ILogger;

Host

  • Sets the host for the server
host?: string;

Reuse port (Bun)

  • When running with Bun, allows multiple processes to bind to the same port. Useful for load-balancing.
reusePort?: boolean;

Header event

  • This event handler gets called before a new WS connection would be created.
  • If you want to add new headers to the upgrade frame's reponse, return them as an array.
headerEvent?: (recievedHeaders: IncomingHttpHeaders) => Array<string> | void;

Max waiter time

  • The maximal waiting time for waiters.
  • Defaults to 800ms
maxWaiterTime?: number;

Custom client class

clientClass?: new (
socket: WebSocketClient,
ip: string | undefined,
server: ZilaServer,
isBrowser: boolean,
headers: { [name: string]: string },
cookies?: Map<string, string>
) => ZilaClient;

Reject banned IPs before connection upgrade

Rejects an incoming connection if its IP's banned before upgrading the HTTP connnection to WS Warning: If this option is turned on, and ZilaWS is ran and/or is accessed with Bun, in most cases the client will not recieve the ban message from the server.

rejectBannedIpBeforeConnectionUpgrade?: boolean;

Restricts which HTTP origins may access the /zilaws/cookiesync endpoint (CORS). If omitted, the server will reflect the Origin header. If provided:

  • Use an array of allowed exact origin strings (e.g. ["https://app.example.com", "http://localhost:3000"]).
  • The special value "*" inside the array will allow any origin (not recommended when credentials are involved). Matching is case-sensitive and must be an exact string match.
cookieSyncAllowedOrigins?: string[];

Sets the name of the cookie which ZilaWS uses to identify sessions. If you are using an auth library like betterAuth consider changing this to the nem of the cookie which the lib uses. Default value: zilaSession

sessionTokenCookieName?: string;