@monkeyplus/flow 6.0.2 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1,3 +1,3 @@
1
1
  export default function renderPage(input: Request | {
2
2
  req?: Request;
3
- }): Response | Promise<Response> | undefined;
3
+ }): Promise<Response | undefined>;
@@ -1,14 +1,36 @@
1
+ let prerenderFetchHandlerPromise;
1
2
  function resolveRequest(input) {
2
3
  if (input instanceof Request) {
3
4
  return input;
4
5
  }
5
6
  return input?.req;
6
7
  }
7
- export default function renderPage(input) {
8
+ async function resolvePrerenderFetchHandler() {
9
+ prerenderFetchHandlerPromise ||= (async () => {
10
+ try {
11
+ const ssrServiceUrl = new URL("../../vite/services/ssr/index.js", import.meta.url);
12
+ const ssrService = await import(
13
+ /* @vite-ignore */
14
+ ssrServiceUrl.href
15
+ );
16
+ const defaultService = ssrService.default;
17
+ const fetchHandler = defaultService?.fetch;
18
+ return typeof fetchHandler === "function" ? fetchHandler.bind(defaultService) : void 0;
19
+ } catch {
20
+ return void 0;
21
+ }
22
+ })();
23
+ return await prerenderFetchHandlerPromise;
24
+ }
25
+ export default async function renderPage(input) {
8
26
  const viteEnvs = globalThis.__nitro_vite_envs__;
9
27
  const request = resolveRequest(input);
28
+ const viteFetchHandler = viteEnvs?.ssr?.fetch;
10
29
  if (!request) {
11
30
  return new Response("Not Found", { status: 404 });
12
31
  }
13
- return viteEnvs?.ssr?.fetch(request);
32
+ if (typeof viteFetchHandler === "function") {
33
+ return viteFetchHandler(request);
34
+ }
35
+ return (await resolvePrerenderFetchHandler())?.(request);
14
36
  }