@modern-js/server-core 3.2.2 → 3.4.0

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.
@@ -40,10 +40,11 @@ const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig })=>({
40
40
  const config = api.getServerConfig();
41
41
  const hooks = api.getHooks();
42
42
  if (!routes) return;
43
- const onFallback = async (reason, error)=>{
43
+ const onFallback = async (reason, error, context)=>{
44
44
  await hooks.fallback.call({
45
45
  reason,
46
- error
46
+ error,
47
+ context
47
48
  });
48
49
  };
49
50
  const getRenderHandlerOptions = {
@@ -102,9 +102,13 @@ var __webpack_exports__ = {};
102
102
  const framework = (0, universal_namespaceObject.cutNameByHyphen)(metaName || 'modern-js');
103
103
  const fallbackHeader = `x-${framework}-ssr-fallback`;
104
104
  let fallbackReason = null;
105
+ const fallbackContext = {
106
+ request: req,
107
+ monitors
108
+ };
105
109
  const fallbackWrapper = async (reason, error)=>{
106
110
  fallbackReason = reason;
107
- return onFallback?.(reason, error);
111
+ return onFallback?.(reason, error, fallbackContext);
108
112
  };
109
113
  if (!routeInfo) return new Response((0, index_js_namespaceObject.createErrorHtml)(404), {
110
114
  status: 404,
@@ -7,10 +7,11 @@ const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig })=>({
7
7
  const config = api.getServerConfig();
8
8
  const hooks = api.getHooks();
9
9
  if (!routes) return;
10
- const onFallback = async (reason, error)=>{
10
+ const onFallback = async (reason, error, context)=>{
11
11
  await hooks.fallback.call({
12
12
  reason,
13
- error
13
+ error,
14
+ context
14
15
  });
15
16
  };
16
17
  const getRenderHandlerOptions = {
@@ -62,9 +62,13 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
62
62
  const framework = cutNameByHyphen(metaName || 'modern-js');
63
63
  const fallbackHeader = `x-${framework}-ssr-fallback`;
64
64
  let fallbackReason = null;
65
+ const fallbackContext = {
66
+ request: req,
67
+ monitors
68
+ };
65
69
  const fallbackWrapper = async (reason, error)=>{
66
70
  fallbackReason = reason;
67
- return onFallback?.(reason, error);
71
+ return onFallback?.(reason, error, fallbackContext);
68
72
  };
69
73
  if (!routeInfo) return new Response(createErrorHtml(404), {
70
74
  status: 404,
@@ -8,10 +8,11 @@ const injectRenderHandlerPlugin = ({ staticGenerate, cacheConfig })=>({
8
8
  const config = api.getServerConfig();
9
9
  const hooks = api.getHooks();
10
10
  if (!routes) return;
11
- const onFallback = async (reason, error)=>{
11
+ const onFallback = async (reason, error, context)=>{
12
12
  await hooks.fallback.call({
13
13
  reason,
14
- error
14
+ error,
15
+ context
15
16
  });
16
17
  };
17
18
  const getRenderHandlerOptions = {
@@ -63,9 +63,13 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
63
63
  const framework = cutNameByHyphen(metaName || 'modern-js');
64
64
  const fallbackHeader = `x-${framework}-ssr-fallback`;
65
65
  let fallbackReason = null;
66
+ const fallbackContext = {
67
+ request: req,
68
+ monitors
69
+ };
66
70
  const fallbackWrapper = async (reason, error)=>{
67
71
  fallbackReason = reason;
68
- return onFallback?.(reason, error);
72
+ return onFallback?.(reason, error, fallbackContext);
69
73
  };
70
74
  if (!routeInfo) return new Response(createErrorHtml(404), {
71
75
  status: 404,
@@ -1,15 +1,20 @@
1
- import type { CacheOption, Container, HttpMethodDecider, MiddlewareContext, ServerRoute } from '@modern-js/types';
1
+ import type { CacheOption, Container, HttpMethodDecider, MiddlewareContext, Monitors, ServerRoute } from '@modern-js/types';
2
2
  import type { Context, MiddlewareHandler } from 'hono';
3
3
  import type { UserConfig } from '../config';
4
4
  import type { Render } from '../render';
5
5
  import type { ServerPlugin } from './plugin';
6
6
  export type { FileChangeEvent, ResetEvent } from '@modern-js/plugin';
7
7
  export type FallbackReason = 'error' | 'header' | 'query' | `header,${string}`;
8
+ export type FallbackContext = {
9
+ request: Request;
10
+ monitors?: Monitors;
11
+ };
8
12
  export type FallbackInput = {
9
13
  reason: FallbackReason;
10
14
  error: unknown;
15
+ context?: FallbackContext;
11
16
  };
12
- export type OnFallback = (reason: FallbackReason, error?: unknown) => Promise<void>;
17
+ export type OnFallback = (reason: FallbackReason, error?: unknown, context?: FallbackContext) => Promise<void>;
13
18
  export type APIServerStartInput = {
14
19
  pwd: string;
15
20
  prefix?: string;
@@ -1,2 +1,2 @@
1
1
  export * from './plugin';
2
- export type { ServerConfig, CacheConfig, OnFallback, FallbackReason, GetRenderHandlerOptions, FileChangeEvent, FallbackInput, WebServerStartInput, APIServerStartInput, ServerMiddleware, MiddlewareObj, } from './base';
2
+ export type { ServerConfig, CacheConfig, OnFallback, FallbackReason, FallbackContext, GetRenderHandlerOptions, FileChangeEvent, FallbackInput, WebServerStartInput, APIServerStartInput, ServerMiddleware, MiddlewareObj, } from './base';
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.2.2",
18
+ "version": "3.4.0",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -71,19 +71,19 @@
71
71
  "flatted": "^3.4.2",
72
72
  "hono": "^4.11.7",
73
73
  "ts-deepmerge": "7.0.3",
74
- "@modern-js/plugin": "3.2.2",
75
- "@modern-js/runtime-utils": "3.2.2",
76
- "@modern-js/utils": "3.2.2"
74
+ "@modern-js/plugin": "3.4.0",
75
+ "@modern-js/runtime-utils": "3.4.0",
76
+ "@modern-js/utils": "3.4.0"
77
77
  },
78
78
  "devDependencies": {
79
- "@rslib/core": "0.21.5",
79
+ "@rslib/core": "0.22.1",
80
80
  "@types/cloneable-readable": "^2.0.3",
81
81
  "@types/merge-deep": "^3.0.3",
82
82
  "@types/node": "^20",
83
83
  "http-proxy-middleware": "^2.0.9",
84
84
  "typescript": "^5",
85
85
  "@modern-js/rslib": "2.68.10",
86
- "@modern-js/types": "3.2.2",
86
+ "@modern-js/types": "3.4.0",
87
87
  "@scripts/rstest-config": "2.66.0"
88
88
  },
89
89
  "sideEffects": false,