UNPKG

@equinor/fusion-framework-vite-plugin-api-service

Version:

Vite plugin for proxying service discovery and mocking

30 lines (29 loc) 1.35 kB
import type { ApiRoute, ServerListener, PluginLogger, ProxyListener } from './types.js'; /** * Options for {@link processRoutes} and the internal `processesRoute` helper. * * @property logger - Optional {@link PluginLogger} for diagnostic messages. * @property onProxyRes - Optional listener invoked on every proxy response, * useful for custom header injection or logging. */ export type ProcessRouteOptions = { logger?: PluginLogger; onProxyRes?: ProxyListener; }; /** * Iterates over a list of {@link ApiRoute} definitions, matches the incoming * request URL against each route using {@link createRouteMatcher}, and * processes the first matching route. * * If a route matches, its extracted path parameters are attached to * `req.params` and the route is handed off to `processesRoute` for * middleware execution or proxy forwarding. When no route matches, the * `next` callback is invoked so the Vite/Connect middleware chain can * continue. * * @param routes - Ordered array of API routes to evaluate. * @param middlewareArgs - The Connect middleware triple `[req, res, next]`. * @param options - Optional processing configuration (logger, proxy * response listener). */ export declare function processRoutes(routes: ApiRoute[], middlewareArgs: Parameters<ServerListener>, options?: ProcessRouteOptions): void;