/** * Create and run Veryfront servers. * * @module server * * @example Composable service server * ```ts * import { createVeryfrontServer } from "veryfront/server"; * * const server = createVeryfrontServer({ * modules: [{ * name: "agent", * handle: (request) => new Response(`Handled ${request.url}`), * }], * }); * * await server.fetch(new Request("https://example.com/health")); * ``` * * @see docs/deployment.md * @see docs/security.md */ import "../../_dnt.polyfills.js"; import { DevServer, type DevServerHandler, type DevServerOptions, type FileWatcherMetrics, type RouteDirectory, startDevServer } from "./dev-server.js"; import { type DiscoveryOptions, type ServerHandle, startProductionServer, type StartProductionServerOptions } from "./production-server.js"; export { DevServer, type DevServerHandler, startDevServer, startProductionServer }; export { gracefullyShutdownProductionServer, type GracefulProductionShutdownOptions, } from "./graceful-shutdown.js"; export { createVeryfrontServer, type CreateVeryfrontServerOptions, type NodeVeryfrontServiceServer, startNodeVeryfrontServer, type StartNodeVeryfrontServerOptions, startVeryfrontServer, type StartVeryfrontServerOptions, type VeryfrontServiceServer, type VeryfrontServiceServerFetch, type VeryfrontServiceServerLogger, type VeryfrontServiceServerModule, type VeryfrontServiceServerModuleResponse, type VeryfrontServiceServerRuntime, type VeryfrontServiceServerRuntimeKind, } from "./service-server.js"; export type { DevServerOptions, DiscoveryOptions, FileWatcherMetrics, RouteDirectory, ServerHandle, StartProductionServerOptions, }; import { ReloadNotifier } from "./reload-notifier.js"; export { ReloadNotifier }; export { RouteDiscovery } from "./dev-server/route-discovery.js"; export type { BuildOptions, BuildStats } from "./build-types.js"; export { defaultDistributedCacheInitializers } from "./distributed-cache-initializers.js"; export { HOSTED_ENVIRONMENT_NAMES, type HostedEnvironmentName, isHostedEnvironmentName, parseProjectDomain, } from "./utils/domain-parser.js"; /** Shared options for both development and production server modes. */ interface BaseServerOptions { /** Project root directory. Defaults to process.cwd(). */ projectDir?: string; port?: number; /** 0.0.0.0 = all interfaces, 127.0.0.1 = localhost only */ bindAddress?: string; signal?: AbortSignal; /** Default project slug when not provided via proxy headers (for tests/local mode) */ defaultProjectSlug?: string; /** Default project ID when not provided via proxy headers (for tests/local mode) */ defaultProjectId?: string; /** * Optional request interceptor for combined mode. * Transforms requests before they're processed by the core request handler. */ requestInterceptor?: (req: Request) => Request | Promise; } /** Options accepted by start dev mode. */ export interface StartDevModeOptions extends BaseServerOptions { mode?: "development"; moduleServerPort?: number; enableHMR?: boolean; enableFastRefresh?: boolean; fileWatcherDebounceMs?: number; } /** Options accepted by start production mode. */ export interface StartProductionModeOptions extends BaseServerOptions { mode?: "production"; /** When true, expose additional debug logging. */ debug?: boolean; /** Default environment for standalone mode (preview or production). Defaults to preview for safety. */ defaultEnvironment?: "preview" | "production"; /** Discovery configuration for AI primitives. Runs discoverAll() before serving. */ discoveryConfig?: DiscoveryOptions; /** Map of local project slugs to their filesystem paths. */ localProjects?: Record; } /** * Server options. Defaults to development mode with HMR. * Set `mode: "production"` for a production server. */ export type StartServerOptions = StartDevModeOptions | StartProductionModeOptions; /** Running server instance with lifecycle controls. */ export interface VeryfrontServer { /** Resolves when the server is ready to accept requests. */ ready: Promise; /** Gracefully stop the server. */ stop: () => Promise; /** The port the server is listening on. */ port: number; /** The full URL the server is listening on. */ url: string; } /** Web API request handler with WebSocket upgrade and HMR helpers. */ export type VeryfrontHandler = ((req: Request, nativeContext?: unknown) => Promise) & { /** * Attach WebSocket upgrade handling to a Node.js HTTP server. * Required for HMR live reload when using an external server like Hono, Express, etc. */ upgrade: (server: unknown) => void; /** * Connect an external WebSocket to the HMR live reload system. * Use this for runtimes that manage WebSocket upgrades natively (e.g. Bun/Elysia) * instead of `handler.upgrade(server)`. */ connectHMR: (ws: WebSocket) => void; /** Release upgrade listeners, sockets, and bootstrap-owned resources. */ dispose: () => Promise; }; /** Create a Veryfront request handler for development or production. */ export declare function createHandler(options?: { projectDir?: string; mode?: "development" | "production"; port?: number; }): Promise; /** * Convert a Web API request handler into a Node.js HTTP request listener. * * @example * ```ts * import { createServer } from "node:http" * import { createHandler, toNodeHandler } from "veryfront" * * const handler = await createHandler() * const server = createServer(toNodeHandler(handler)) * ``` */ export { toNodeHandler } from "./node-handler.js"; /** * Start a Veryfront server in development or production mode. * * This is the primary entry point for running a Veryfront server. * Defaults to development mode when `mode` is not specified. */ export declare function startServer(options?: StartServerOptions): Promise; //# sourceMappingURL=index.d.ts.map