Development

srvkit provides a live-reloading dev server that updates in place when your files change. There is no restart — the fetch, error, and middleware handlers are swapped without dropping connections.

Starting the dev server

When you run the dev command for your build tool, srvkit starts a development server:

Vite
Rsbuild
vite dev

The server starts on localhost:3001 by default and watches your entry file for changes.

Entry file

By default, srvkit looks for the entry file at ./src/index.ts, falling back to ./src/index.js if the TypeScript file does not exist. You can override this with the entry option:

Vite
Rsbuild
vite.config.ts
import { defineConfig } from "vite";
import { srvkit } from "@srvkit/vite/plugin";

export default defineConfig({
    plugins: [
        srvkit({
            entry: "./src/server.ts",
        }),
    ],
});

How live reload works

On startup, srvkit reads the default export from your entry file and starts serving requests through the fetch handler.

When a file change is detected, the module is re-imported. The new options are passed to the live server, which swaps the handlers in place. In-flight requests continue on the old handler — no connections are dropped.

If a module reload fails (for example, due to a syntax error), srvkit keeps serving the previous working handler so your dev server remains responsive. The Vite plugin retries failed reloads up to three times with increasing backoff.

Configuration

Dev server options are set through the plugin configuration:

Vite
Rsbuild
vite.config.ts
import { defineConfig } from "vite";
import { srvkit } from "@srvkit/vite/plugin";

export default defineConfig({
    plugins: [
        srvkit({
            dev: {
                host: "0.0.0.0",
                port: 4000,
            },
        }),
    ],
});

dev.host

The hostname the dev server binds to. Defaults to localhost.

Set to "0.0.0.0" to make the server accessible on your local network.

dev.port

The port the dev server listens on. Defaults to 3001.

srvkit({
    dev: {
        port: 4001,
    },
});

HTTPS

To enable HTTPS in development, provide certificate and key paths (or inline PEM content):

srvkit({
    dev: {
        https: {
            cert: "./certs/local.crt",
            key: "./certs/local.key",
            passphrase: "optional-passphrase",
        },
    },
});

The passphrase field is optional and only needed if your private key is encrypted.