74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { ServerHandler } from "srvx";
|
|
|
|
//#region src/loader.d.ts
|
|
declare const defaultExts: string[];
|
|
declare const defaultEntries: string[];
|
|
/**
|
|
* Options for loading a server entry module.
|
|
*/
|
|
type LoadOptions = {
|
|
/**
|
|
* Path or URL to the server entry file.
|
|
*
|
|
* If not provided, common entry points will be searched automatically.
|
|
*/
|
|
entry?: string;
|
|
/**
|
|
* Base directory for resolving relative paths.
|
|
*
|
|
* @default "."
|
|
*/
|
|
dir?: string;
|
|
/**
|
|
* Set to `false` to disable interception of `http.Server.listen` to detect legacy handlers.
|
|
*
|
|
* @default true
|
|
*/
|
|
interceptHttpListen?: boolean;
|
|
/**
|
|
* Set to `false` to disable Node.js handler (req, res) compatibility.
|
|
*/
|
|
nodeCompat?: boolean;
|
|
/**
|
|
* Hook called after the module is loaded to allow for custom processing.
|
|
*
|
|
* You can return a modified version of the module if needed.
|
|
*/
|
|
onLoad?: (module: unknown) => any;
|
|
};
|
|
/**
|
|
* Result of loading a server entry module.
|
|
*/
|
|
type LoadedServerEntry = {
|
|
/**
|
|
* The web fetch handler extracted from the loaded module.
|
|
*
|
|
* This is resolved from `module.fetch`, `module.default.fetch`,
|
|
* or upgraded from a legacy Node.js handler.
|
|
*/
|
|
fetch?: ServerHandler;
|
|
/**
|
|
* The raw loaded module.
|
|
*/
|
|
module?: any;
|
|
/**
|
|
* Whether the handler was upgraded from a legacy Node.js HTTP handler.
|
|
*
|
|
* When `true`, the original module exported a Node.js-style `(req, res)` handler
|
|
* that has been wrapped for web fetch compatibility.
|
|
*/
|
|
nodeCompat?: boolean;
|
|
/**
|
|
* The resolved `file://` URL of the loaded entry module.
|
|
*/
|
|
url?: string;
|
|
/**
|
|
* Whether the specified entry file was not found.
|
|
*
|
|
* When `true`, no valid entry point could be located.
|
|
*/
|
|
notFound?: boolean;
|
|
};
|
|
declare function loadServerEntry(opts: LoadOptions): Promise<LoadedServerEntry>;
|
|
//#endregion
|
|
export { LoadOptions, LoadedServerEntry, defaultEntries, defaultExts, loadServerEntry }; |