UNPKG

uws-autoload

Version:

Plugin for [µWebSockets.js](https://github.com/uNetworking/uWebSockets.js) that autoloads all routes in a directory.

47 lines (44 loc) 1.23 kB
import { TemplatedApp } from 'uWebSockets.js'; type SoftString<T extends string> = T | (string & {}); interface AutoloadRoutesOptions { /** * Import a specific `export` from a file * @example import first export * ```ts * importKey: 'default' || (file) => Object.keys(file).at(0) * ``` * @default 'default' */ importKey?: SoftString<'default'> | ((file: unknown) => string); /** * Throws an error if no matches are found * @default true */ failGlob?: boolean; /** * Pattern * @example pattern only .ts files * ```ts * pattern: '**\/*.ts' * ``` * @default '**\/*.{ts,tsx,mjs,js,jsx,cjs}' */ pattern?: string; /** * Prefix to add to routes * @example prefix for APIs * ```ts * prefix: '/api' * ``` * @default '' */ prefix?: string; routesDir?: string; /** * Skip imports where needed `export` not defined * @default false */ skipImportErrors?: boolean; } declare const autoloadRoutes: (app: TemplatedApp, { importKey, failGlob, pattern, prefix, routesDir, skipImportErrors }: AutoloadRoutesOptions) => Promise<TemplatedApp>; export { autoloadRoutes };