UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

41 lines (40 loc) 1.67 kB
import { createWorkerHandler } from "./server/workerHandler.mjs"; import { compileManifest } from "./createHandleRequest.mjs"; import { getFetchStaticHtml, setFetchStaticHtml } from "./server/staticHtmlFetcher.mjs"; import { setServerGlobals } from "./server/setServerGlobals.mjs"; import { setupBuildInfo } from "./server/setupBuildOptions.mjs"; import { createWorkerHandler as createWorkerHandler2 } from "./server/workerHandler.mjs"; async function createServer(options) { const manifest = options.manifest || options.buildInfo?.manifest; if (!manifest) throw new Error("one/headless-server: manifest is required"); const buildInfo = { manifest, oneOptions: options.oneOptions, routeToBuildInfo: options.buildInfo?.routeToBuildInfo ?? {}, routeMap: options.buildInfo?.routeMap ?? {}, preloads: options.buildInfo?.preloads ?? {}, cssPreloads: options.buildInfo?.cssPreloads ?? {} }; setupBuildInfo(buildInfo); setServerGlobals(); const handler = createWorkerHandler2({ oneOptions: options.oneOptions, buildInfo, lazyRoutes: options.routes }); return { /** handle an incoming request — returns Response or null (unmatched) */ fetch: handler.handleRequest, /** hot-swap the route table without recreating the server */ updateRoutes(newManifest, newRoutes) { const newBuildInfo = { ...buildInfo, manifest: newManifest }; setupBuildInfo(newBuildInfo); handler.updateRoutes(newBuildInfo, newRoutes); } }; } export { compileManifest, createServer, createWorkerHandler, getFetchStaticHtml, setFetchStaticHtml }; //# sourceMappingURL=headless-server.mjs.map