@monkeyplus/flow 6.0.2 → 6.0.4

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.4",
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,49 @@
1
+ import { resolve } from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ let prerenderFetchHandlerPromise;
4
+ function resolvePrerenderServiceUrls() {
5
+ const cwd = process.cwd();
6
+ return [
7
+ pathToFileURL(resolve(cwd, "node_modules/.nitro/vite/services/ssr/index.js")).href,
8
+ pathToFileURL(resolve(cwd, ".nitro/vite/services/ssr/index.js")).href,
9
+ new URL("../../vite/services/ssr/index.js", import.meta.url).href
10
+ ];
11
+ }
1
12
  function resolveRequest(input) {
2
13
  if (input instanceof Request) {
3
14
  return input;
4
15
  }
5
16
  return input?.req;
6
17
  }
7
- export default function renderPage(input) {
18
+ async function resolvePrerenderFetchHandler() {
19
+ prerenderFetchHandlerPromise ||= (async () => {
20
+ for (const ssrServiceUrl of resolvePrerenderServiceUrls()) {
21
+ try {
22
+ const ssrService = await import(
23
+ /* @vite-ignore */
24
+ ssrServiceUrl
25
+ );
26
+ const defaultService = ssrService.default;
27
+ const fetchHandler = defaultService?.fetch;
28
+ if (typeof fetchHandler === "function") {
29
+ return fetchHandler.bind(defaultService);
30
+ }
31
+ } catch {
32
+ }
33
+ }
34
+ return void 0;
35
+ })();
36
+ return await prerenderFetchHandlerPromise;
37
+ }
38
+ export default async function renderPage(input) {
8
39
  const viteEnvs = globalThis.__nitro_vite_envs__;
9
40
  const request = resolveRequest(input);
41
+ const viteFetchHandler = viteEnvs?.ssr?.fetch;
10
42
  if (!request) {
11
43
  return new Response("Not Found", { status: 404 });
12
44
  }
13
- return viteEnvs?.ssr?.fetch(request);
45
+ if (typeof viteFetchHandler === "function") {
46
+ return viteFetchHandler(request);
47
+ }
48
+ return (await resolvePrerenderFetchHandler())?.(request);
14
49
  }