# Register MSW request handlers

By allowing consumers to register dynamic request handlers, Squide enables developers to build scalable modular applications with well-defined boundaries. Each module contributes its own Mock Service Workers, which the host assembles into a unified set.

For more details, refer to the reference documentation.

# Register an handler

Before registering a handler, make sure MSW is enabled by checking with isMswEnabled. This prevents MSW handlers from being registered in production.

import type { ModuleRegisterFunction, FireflyRuntime } from "@squide/firefly";

export const register: ModuleRegisterFunction<FireflyRuntime> = runtime => {
    if (runtime.isMswEnabled) {
        // Files that includes an import to the "msw" package are included dynamically to prevent adding
        // unused MSW code in production bundles.
        const requestHandlers = (await import("../mocks/handlers.ts")).requestHandlers;

        runtime.registerRequestHandlers(requestHandlers);
    }
};

# Setup MSW

Refer to the Setup MSW integration guide.