UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

45 lines (42 loc) • 2.52 kB
import { createWorkerHandler, createWorkerHandler as createWorkerHandler$1 } from "./server/workerHandler.native.js"; import { compileManifest } from "./createHandleRequest.native.js"; import { getFetchStaticHtml, setFetchStaticHtml } from "./server/staticHtmlFetcher.native.js"; import { setServerGlobals } from "./server/setServerGlobals.native.js"; import { setupBuildInfo } from "./server/setupBuildOptions.native.js"; async function createServer(options) { var _ref, _ref1, _ref2; var _options_buildInfo, _options_buildInfo1, _options_buildInfo2, _options_buildInfo3, _options_buildInfo4, _options_buildInfo5; var manifest = options.manifest || ((_options_buildInfo = options.buildInfo) === null || _options_buildInfo === void 0 ? void 0 : _options_buildInfo.manifest); if (!manifest) throw new Error("one/headless-server: manifest is required"); var buildInfo = { manifest, oneOptions: options.oneOptions, routeToBuildInfo: (_ref = (_options_buildInfo1 = options.buildInfo) === null || _options_buildInfo1 === void 0 ? void 0 : _options_buildInfo1.routeToBuildInfo) !== null && _ref !== void 0 ? _ref : {}, cssContentsByPath: (_options_buildInfo2 = options.buildInfo) === null || _options_buildInfo2 === void 0 ? void 0 : _options_buildInfo2.cssContentsByPath, routeMap: (_options_buildInfo3 = options.buildInfo) === null || _options_buildInfo3 === void 0 ? void 0 : _options_buildInfo3.routeMap, preloads: (_ref1 = (_options_buildInfo4 = options.buildInfo) === null || _options_buildInfo4 === void 0 ? void 0 : _options_buildInfo4.preloads) !== null && _ref1 !== void 0 ? _ref1 : {}, cssPreloads: (_ref2 = (_options_buildInfo5 = options.buildInfo) === null || _options_buildInfo5 === void 0 ? void 0 : _options_buildInfo5.cssPreloads) !== null && _ref2 !== void 0 ? _ref2 : {} }; setupBuildInfo(buildInfo); setServerGlobals(); var handler = createWorkerHandler$1({ 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) { var newBuildInfo = { ...buildInfo, manifest: newManifest }; setupBuildInfo(newBuildInfo); handler.updateRoutes(newBuildInfo, newRoutes); } }; } export { compileManifest, createServer, createWorkerHandler, getFetchStaticHtml, setFetchStaticHtml }; //# sourceMappingURL=headless-server.native.js.map