@modern-js/main-doc 2.67.4 → 2.67.6

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.
Files changed (198) hide show
  1. package/docs/en/apis/app/hooks/server/server.mdx +10 -0
  2. package/docs/en/apis/app/hooks/src/routes.mdx +3 -3
  3. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +30 -0
  4. package/docs/en/components/enable-bff.mdx +1 -27
  5. package/docs/en/components/rsbuild-config-tooltip.mdx +2 -2
  6. package/docs/en/components/tech-stack-node-framework.mdx +1 -1
  7. package/docs/en/configure/app/dev/asset-prefix.mdx +2 -3
  8. package/docs/en/configure/app/dev/client.mdx +2 -3
  9. package/docs/en/configure/app/dev/hmr.mdx +2 -3
  10. package/docs/en/configure/app/dev/live-reload.mdx +2 -3
  11. package/docs/en/configure/app/dev/progress-bar.mdx +2 -3
  12. package/docs/en/configure/app/dev/setup-middlewares.mdx +2 -3
  13. package/docs/en/configure/app/dev/watch-files.mdx +2 -3
  14. package/docs/en/configure/app/dev/write-to-disk.mdx +2 -3
  15. package/docs/en/configure/app/html/app-icon.mdx +2 -3
  16. package/docs/en/configure/app/html/crossorigin.mdx +2 -3
  17. package/docs/en/configure/app/html/favicon.mdx +2 -3
  18. package/docs/en/configure/app/html/inject.mdx +2 -3
  19. package/docs/en/configure/app/html/meta.mdx +2 -3
  20. package/docs/en/configure/app/html/mount-id.mdx +2 -3
  21. package/docs/en/configure/app/html/output-structure.mdx +2 -3
  22. package/docs/en/configure/app/html/script-loading.mdx +2 -3
  23. package/docs/en/configure/app/html/tags.mdx +2 -3
  24. package/docs/en/configure/app/html/template-parameters.mdx +2 -3
  25. package/docs/en/configure/app/html/template.mdx +2 -3
  26. package/docs/en/configure/app/html/title.mdx +2 -3
  27. package/docs/en/configure/app/output/asset-prefix.mdx +2 -3
  28. package/docs/en/configure/app/output/charset.mdx +2 -3
  29. package/docs/en/configure/app/output/copy.mdx +2 -3
  30. package/docs/en/configure/app/output/css-modules.mdx +2 -3
  31. package/docs/en/configure/app/output/data-uri-limit.mdx +2 -3
  32. package/docs/en/configure/app/output/dist-path.mdx +2 -4
  33. package/docs/en/configure/app/output/externals.mdx +2 -3
  34. package/docs/en/configure/app/output/filename-hash.mdx +2 -3
  35. package/docs/en/configure/app/output/filename.mdx +2 -3
  36. package/docs/en/configure/app/output/inject-styles.mdx +2 -3
  37. package/docs/en/configure/app/output/inline-scripts.mdx +2 -3
  38. package/docs/en/configure/app/output/inline-styles.mdx +2 -3
  39. package/docs/en/configure/app/output/legal-comments.mdx +2 -3
  40. package/docs/en/configure/app/output/minify.mdx +2 -3
  41. package/docs/en/configure/app/output/override-browserslist.mdx +2 -3
  42. package/docs/en/configure/app/output/polyfill.mdx +2 -3
  43. package/docs/en/configure/app/output/source-map.mdx +2 -3
  44. package/docs/en/configure/app/performance/build-cache.mdx +2 -3
  45. package/docs/en/configure/app/performance/bundle-analyze.mdx +2 -3
  46. package/docs/en/configure/app/performance/chunk-split.mdx +2 -3
  47. package/docs/en/configure/app/performance/dns-prefetch.mdx +2 -3
  48. package/docs/en/configure/app/performance/preconnect.mdx +2 -3
  49. package/docs/en/configure/app/performance/prefetch.mdx +2 -3
  50. package/docs/en/configure/app/performance/preload.mdx +2 -3
  51. package/docs/en/configure/app/performance/print-file-size.mdx +2 -3
  52. package/docs/en/configure/app/performance/profile.mdx +2 -3
  53. package/docs/en/configure/app/performance/remove-console.mdx +2 -3
  54. package/docs/en/configure/app/performance/remove-moment-locale.mdx +2 -3
  55. package/docs/en/configure/app/plugins.mdx +13 -33
  56. package/docs/en/configure/app/runtime/master-app.mdx +1 -5
  57. package/docs/en/configure/app/runtime/plugins.mdx +58 -0
  58. package/docs/en/configure/app/security/nonce.mdx +2 -3
  59. package/docs/en/configure/app/security/sri.mdx +0 -1
  60. package/docs/en/configure/app/server/port.mdx +2 -3
  61. package/docs/en/configure/app/source/alias-strategy.mdx +2 -3
  62. package/docs/en/configure/app/source/alias.mdx +2 -3
  63. package/docs/en/configure/app/source/decorators.mdx +2 -3
  64. package/docs/en/configure/app/source/define.mdx +2 -3
  65. package/docs/en/configure/app/source/exclude.mdx +2 -3
  66. package/docs/en/configure/app/source/include.mdx +2 -3
  67. package/docs/en/configure/app/source/pre-entry.mdx +2 -3
  68. package/docs/en/configure/app/source/transform-import.mdx +2 -3
  69. package/docs/en/configure/app/tools/css-extract.mdx +2 -3
  70. package/docs/en/configure/app/tools/css-loader.mdx +2 -2
  71. package/docs/en/configure/app/tools/html-plugin.mdx +7 -3
  72. package/docs/en/configure/app/tools/lightningcss-loader.mdx +2 -3
  73. package/docs/en/configure/app/tools/postcss.mdx +2 -3
  74. package/docs/en/configure/app/tools/rspack.mdx +2 -3
  75. package/docs/en/configure/app/tools/style-loader.mdx +2 -3
  76. package/docs/en/configure/app/tools/swc.mdx +1 -1
  77. package/docs/en/configure/app/usage.mdx +1 -1
  78. package/docs/en/guides/advanced-features/bff/extend-server.mdx +33 -82
  79. package/docs/en/guides/advanced-features/bff/frameworks.mdx +12 -68
  80. package/docs/en/guides/advanced-features/bff.mdx +1 -1
  81. package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
  82. package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -1
  83. package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +2 -0
  84. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  85. package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +44 -0
  86. package/docs/en/guides/advanced-features/web-server.mdx +378 -14
  87. package/docs/en/guides/basic-features/data/data-fetch.mdx +2 -1
  88. package/docs/en/guides/basic-features/deploy.mdx +3 -3
  89. package/docs/en/guides/basic-features/html.mdx +3 -3
  90. package/docs/en/guides/basic-features/output-files.mdx +0 -28
  91. package/docs/en/guides/basic-features/render/ssr.mdx +2 -2
  92. package/docs/en/guides/concept/entries.mdx +1 -1
  93. package/docs/en/plugin/cli-plugins/api.mdx +6 -0
  94. package/docs/en/plugin/runtime-plugins/api.mdx +37 -12
  95. package/docs/en/tutorials/first-app/c04-routes.mdx +4 -2
  96. package/docs/en/tutorials/first-app/c05-loader.mdx +5 -2
  97. package/docs/zh/apis/app/hooks/server/server.mdx +10 -0
  98. package/docs/zh/apis/app/hooks/src/routes.mdx +3 -3
  99. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +31 -0
  100. package/docs/zh/components/enable-bff.mdx +2 -27
  101. package/docs/zh/components/rsbuild-config-tooltip.mdx +2 -2
  102. package/docs/zh/components/tech-stack-node-framework.mdx +1 -1
  103. package/docs/zh/configure/app/dev/asset-prefix.mdx +2 -3
  104. package/docs/zh/configure/app/dev/client.mdx +2 -3
  105. package/docs/zh/configure/app/dev/hmr.mdx +2 -3
  106. package/docs/zh/configure/app/dev/live-reload.mdx +2 -3
  107. package/docs/zh/configure/app/dev/progress-bar.mdx +2 -3
  108. package/docs/zh/configure/app/dev/setup-middlewares.mdx +2 -3
  109. package/docs/zh/configure/app/dev/watch-files.mdx +2 -3
  110. package/docs/zh/configure/app/dev/write-to-disk.mdx +2 -3
  111. package/docs/zh/configure/app/html/app-icon.mdx +2 -3
  112. package/docs/zh/configure/app/html/crossorigin.mdx +2 -3
  113. package/docs/zh/configure/app/html/favicon.mdx +2 -3
  114. package/docs/zh/configure/app/html/inject.mdx +2 -3
  115. package/docs/zh/configure/app/html/meta.mdx +2 -3
  116. package/docs/zh/configure/app/html/mount-id.mdx +2 -3
  117. package/docs/zh/configure/app/html/output-structure.mdx +2 -3
  118. package/docs/zh/configure/app/html/script-loading.mdx +2 -3
  119. package/docs/zh/configure/app/html/tags.mdx +2 -3
  120. package/docs/zh/configure/app/html/template-parameters.mdx +2 -3
  121. package/docs/zh/configure/app/html/template.mdx +2 -3
  122. package/docs/zh/configure/app/html/title.mdx +2 -3
  123. package/docs/zh/configure/app/output/asset-prefix.mdx +2 -3
  124. package/docs/zh/configure/app/output/charset.mdx +2 -3
  125. package/docs/zh/configure/app/output/copy.mdx +2 -3
  126. package/docs/zh/configure/app/output/css-modules.mdx +2 -3
  127. package/docs/zh/configure/app/output/data-uri-limit.mdx +2 -3
  128. package/docs/zh/configure/app/output/dist-path.mdx +2 -4
  129. package/docs/zh/configure/app/output/externals.mdx +2 -3
  130. package/docs/zh/configure/app/output/filename-hash.mdx +2 -3
  131. package/docs/zh/configure/app/output/filename.mdx +2 -3
  132. package/docs/zh/configure/app/output/inject-styles.mdx +2 -3
  133. package/docs/zh/configure/app/output/inline-scripts.mdx +2 -3
  134. package/docs/zh/configure/app/output/inline-styles.mdx +2 -3
  135. package/docs/zh/configure/app/output/legal-comments.mdx +2 -3
  136. package/docs/zh/configure/app/output/minify.mdx +2 -3
  137. package/docs/zh/configure/app/output/override-browserslist.mdx +2 -3
  138. package/docs/zh/configure/app/output/polyfill.mdx +2 -3
  139. package/docs/zh/configure/app/output/source-map.mdx +2 -3
  140. package/docs/zh/configure/app/performance/build-cache.mdx +2 -3
  141. package/docs/zh/configure/app/performance/bundle-analyze.mdx +2 -3
  142. package/docs/zh/configure/app/performance/chunk-split.mdx +2 -3
  143. package/docs/zh/configure/app/performance/dns-prefetch.mdx +2 -3
  144. package/docs/zh/configure/app/performance/preconnect.mdx +2 -3
  145. package/docs/zh/configure/app/performance/prefetch.mdx +2 -3
  146. package/docs/zh/configure/app/performance/preload.mdx +2 -3
  147. package/docs/zh/configure/app/performance/print-file-size.mdx +2 -3
  148. package/docs/zh/configure/app/performance/profile.mdx +2 -3
  149. package/docs/zh/configure/app/performance/remove-console.mdx +2 -3
  150. package/docs/zh/configure/app/performance/remove-moment-locale.mdx +2 -3
  151. package/docs/zh/configure/app/plugins.mdx +3 -24
  152. package/docs/zh/configure/app/runtime/master-app.mdx +1 -5
  153. package/docs/zh/configure/app/runtime/plugins.mdx +58 -0
  154. package/docs/zh/configure/app/security/nonce.mdx +2 -3
  155. package/docs/zh/configure/app/security/sri.mdx +0 -1
  156. package/docs/zh/configure/app/server/port.mdx +2 -3
  157. package/docs/zh/configure/app/source/alias-strategy.mdx +2 -3
  158. package/docs/zh/configure/app/source/alias.mdx +2 -3
  159. package/docs/zh/configure/app/source/decorators.mdx +2 -3
  160. package/docs/zh/configure/app/source/define.mdx +2 -3
  161. package/docs/zh/configure/app/source/exclude.mdx +2 -3
  162. package/docs/zh/configure/app/source/include.mdx +2 -3
  163. package/docs/zh/configure/app/source/pre-entry.mdx +2 -3
  164. package/docs/zh/configure/app/source/transform-import.mdx +2 -3
  165. package/docs/zh/configure/app/tools/css-extract.mdx +2 -3
  166. package/docs/zh/configure/app/tools/css-loader.mdx +2 -3
  167. package/docs/zh/configure/app/tools/html-plugin.mdx +6 -3
  168. package/docs/zh/configure/app/tools/lightningcss-loader.mdx +2 -3
  169. package/docs/zh/configure/app/tools/postcss.mdx +2 -3
  170. package/docs/zh/configure/app/tools/rspack.mdx +2 -3
  171. package/docs/zh/configure/app/tools/style-loader.mdx +2 -3
  172. package/docs/zh/configure/app/tools/swc.mdx +1 -1
  173. package/docs/zh/configure/app/usage.mdx +1 -1
  174. package/docs/zh/guides/advanced-features/bff/extend-server.mdx +28 -76
  175. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +6 -66
  176. package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -1
  177. package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +44 -0
  178. package/docs/zh/guides/advanced-features/web-server.mdx +375 -18
  179. package/docs/zh/guides/basic-features/deploy.mdx +4 -3
  180. package/docs/zh/guides/basic-features/output-files.mdx +0 -28
  181. package/docs/zh/plugin/cli-plugins/api.mdx +6 -0
  182. package/docs/zh/plugin/runtime-plugins/api.mdx +37 -12
  183. package/docs/zh/tutorials/first-app/c04-routes.mdx +4 -2
  184. package/docs/zh/tutorials/first-app/c05-loader.mdx +4 -1
  185. package/package.json +7 -4
  186. package/rspress.config.ts +16 -1
  187. package/src/components/RsbuildLink/index.tsx +2 -2
  188. package/src/i18n/index.ts +1 -1
  189. package/src/index.ts +1 -5
  190. package/src/pages/index.tsx +3 -3
  191. package/docs/en/apis/app/hooks/api/middleware.mdx +0 -11
  192. package/docs/en/apis/app/runtime/bff/hook.mdx +0 -44
  193. package/docs/en/apis/app/runtime/bff/use-context.mdx +0 -38
  194. package/docs/en/configure/app/bff/enable-handle-web.mdx +0 -24
  195. package/docs/zh/apis/app/hooks/api/middleware.mdx +0 -11
  196. package/docs/zh/apis/app/runtime/bff/hook.mdx +0 -44
  197. package/docs/zh/apis/app/runtime/bff/use-context.mdx +0 -38
  198. package/docs/zh/configure/app/bff/enable-handle-web.mdx +0 -24
package/rspress.config.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import path from 'path';
2
+ import { pluginSass } from '@rsbuild/plugin-sass';
3
+ import { pluginLlms } from '@rspress/plugin-llms';
4
+ import { transformerNotationHighlight } from '@shikijs/transformers';
2
5
  import { defineConfig } from 'rspress/config';
3
6
 
4
7
  const docPath = path.join(__dirname, 'docs');
5
8
 
6
9
  export default defineConfig({
7
10
  root: docPath,
11
+ title: 'Modern.js',
12
+ description:
13
+ 'The Modern.js framework is a progressive web framework based on React. At ByteDance, we use Modern.js to build upper-level frameworks that have supported the development of thousands of web applications.',
8
14
  base: '/',
9
15
  logo: 'https://lf-cdn-tos.bytescm.com/obj/static/webinfra/modern-js-website/assets/images/images/modernjs-logo.svg',
10
16
  icon: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico',
@@ -12,8 +18,11 @@ export default defineConfig({
12
18
  themeDir: path.join(__dirname, 'src'),
13
19
  markdown: {
14
20
  checkDeadLinks: true,
15
- experimentalMdxRs: true,
21
+ shiki: {
22
+ transformers: [transformerNotationHighlight()],
23
+ },
16
24
  },
25
+ plugins: [pluginLlms()],
17
26
  search: {
18
27
  codeBlocks: true,
19
28
  },
@@ -58,6 +67,11 @@ export default defineConfig({
58
67
  text: 'Edit this page on GitHub',
59
68
  },
60
69
  socialLinks: [
70
+ {
71
+ icon: 'discord',
72
+ mode: 'link',
73
+ content: 'https://discord.gg/qPCqYg38De',
74
+ },
61
75
  {
62
76
  icon: 'github',
63
77
  mode: 'link',
@@ -91,5 +105,6 @@ export default defineConfig({
91
105
  '@site': require('path').resolve(__dirname),
92
106
  },
93
107
  },
108
+ plugins: [pluginSass()],
94
109
  },
95
110
  });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useLang } from 'rspress/runtime';
3
3
 
4
- const RsbuildLInk = ({ configName }: { configName: string }) => {
4
+ const RsbuildLink = ({ configName }: { configName: string }) => {
5
5
  const lang = useLang();
6
6
  const href = `https://rsbuild.dev/${lang === 'zh' ? 'zh/' : ''}config/${configName
7
7
  .split('.')
@@ -16,4 +16,4 @@ const RsbuildLInk = ({ configName }: { configName: string }) => {
16
16
  );
17
17
  };
18
18
 
19
- export default RsbuildLInk;
19
+ export default RsbuildLink;
package/src/i18n/index.ts CHANGED
@@ -9,7 +9,7 @@ const translations = {
9
9
 
10
10
  export function useUrl(url: string) {
11
11
  const lang = useLang();
12
- return withBase(lang === 'zh' ? url : `/en${url}`);
12
+ return withBase(lang === 'zh' ? `/zh${url}` : url);
13
13
  }
14
14
 
15
15
  export function useI18n() {
package/src/index.ts CHANGED
@@ -1,9 +1,5 @@
1
- import Theme from 'rspress/theme';
2
1
  import HomeLayout from './pages';
3
2
 
4
- export default {
5
- ...Theme,
6
- HomeLayout,
7
- };
3
+ export { HomeLayout };
8
4
 
9
5
  export * from 'rspress/theme';
@@ -1,6 +1,6 @@
1
1
  import clsx from 'clsx';
2
2
  import { useEffect } from 'react';
3
- import { Helmet, useLocation } from 'rspress/runtime';
3
+ import { Head, useLocation } from 'rspress/runtime';
4
4
  import ContentCard from '../components/ContentCard';
5
5
  import { FeatureLayout } from '../components/FeatureLayout';
6
6
  import Footer from '../components/Footer';
@@ -94,7 +94,7 @@ export default function Home() {
94
94
 
95
95
  return (
96
96
  <div>
97
- <Helmet>
97
+ <Head>
98
98
  <html className="dark" />
99
99
  <script>window.MODERN_THEME = 'dark';</script>
100
100
  <style type="text/css">{`
@@ -102,7 +102,7 @@ export default function Home() {
102
102
  display: none!important;
103
103
  }
104
104
  `}</style>
105
- </Helmet>
105
+ </Head>
106
106
  <HomepageHeader />
107
107
  <main className={styles['homepage-main']}>
108
108
  <FeatureLayout>
@@ -1,11 +0,0 @@
1
- ---
2
- title: _app.[tj]s
3
- sidebar_position: 2
4
- ---
5
- # _app.[tj]s
6
-
7
- This file can add pre-middleware to BFF functions. For detailed information, refer to [Extend BFF Server](/guides/advanced-features/bff/extend-server).
8
-
9
- :::note
10
- For specific examples, please refer to [hook](/apis/app/runtime/bff/hook).
11
- :::
@@ -1,44 +0,0 @@
1
- ---
2
- title: hook
3
- ---
4
- # hook
5
-
6
- Used to add framework middleware under BFF function mode, the middleware will execute before BFF function.
7
-
8
- ## Usage
9
-
10
- according to the framework extend plugin, export from the corresponding namespace:
11
-
12
- ```ts
13
- import { hook } from '@modern-js/runtime/{namespace}';
14
- ```
15
-
16
- ## Function Signature
17
-
18
- ```ts
19
- type HookOptions = {
20
- addMiddleware: string | function;
21
- };
22
-
23
- function hook(options: HookOptions): void;
24
- ```
25
-
26
- ### Input
27
-
28
- - `options`: a range of hooks provided by Modern.js.
29
- - `addMiddleware`: add middlewares for BFF.
30
-
31
- ## Example
32
-
33
- middleware for different frameworks should be different(an example is when using the koa framework):
34
-
35
- ```ts title=api/_app.ts
36
- import { hook } from '@modern-js/runtime/koa';
37
-
38
- export default hook(({ addMiddleware }) => {
39
- addMiddleware(async (ctx, next) => {
40
- ctx.req.query.id = 'koa';
41
- await next();
42
- });
43
- });
44
- ```
@@ -1,38 +0,0 @@
1
- ---
2
- title: useContext
3
- ---
4
- # useContext
5
-
6
- Used to get the request context in the BFF function.
7
-
8
- ## Usage
9
-
10
- according to the framework extend plugin, export from the corresponding namespace:
11
-
12
- ```ts
13
- import { useContext } from '@modern-js/runtime/{namespace}';
14
- ```
15
-
16
- ## Function Signature
17
-
18
- `function useContext(): any`
19
-
20
- ## Example
21
-
22
- Developers can get more request information through `context`, such as browser UA(an example is when using the koa framework):
23
-
24
- ```ts
25
- import { useContext } from '@modern-js/runtime/koa';
26
-
27
- export async function get() {
28
- const ctx = useContext();
29
- return ctx.req.headers['user-agent'];
30
- }
31
- ```
32
-
33
- :::caution
34
- only in BFF function, `useContext` API can be used.
35
-
36
- :::
37
-
38
- Although the `useContext` API is supported in any framework extend plugin, the types of return values are different.
@@ -1,24 +0,0 @@
1
- ---
2
- title: enableHandleWeb
3
- ---
4
-
5
- # bff.enableHandleWeb
6
-
7
- - **Type:** `boolean`
8
- - **Default:** `false`
9
-
10
- import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
11
-
12
- <EnableBFFCaution />
13
-
14
- By default, the BFF service can only handle requests for BFF APIs.
15
-
16
- When this value is set to `true`, page request will also pass through BFF, and the default logic for page rendering built in Modern.js will run as the last middleware of the BFF service.
17
-
18
- ```ts title="modern.config.ts"
19
- export default defineConfig({
20
- bff: {
21
- enableHandleWeb: true,
22
- },
23
- });
24
- ```
@@ -1,11 +0,0 @@
1
- ---
2
- title: _app.[tj]s
3
- sidebar_position: 2
4
- ---
5
- # _app.[tj]s
6
-
7
- 该文件可以为 BFF 函数添加前置中间件,详细内容参考 [扩展 BFF Server](/guides/advanced-features/bff/extend-server)。
8
-
9
- :::note
10
- 具体示例请参考 [hook](/apis/app/runtime/bff/hook)。
11
- :::
@@ -1,44 +0,0 @@
1
- ---
2
- title: hook
3
- ---
4
- # hook
5
-
6
- 用于在 BFF 函数写法下添加框架中间件,添加的中间件的执行会在 BFF 函数定义的路由之前。
7
-
8
- ## 使用姿势
9
-
10
- 根据使用的框架拓展插件,从对应的命名空间中导出:
11
-
12
- ```ts
13
- import { hook } from '@modern-js/runtime/{namespace}';
14
- ```
15
-
16
- ## 函数签名
17
-
18
- ```ts
19
- type HookOptions = {
20
- addMiddleware: string | function;
21
- };
22
-
23
- function hook(options: HookOptions): void;
24
- ```
25
-
26
- ### 参数
27
-
28
- - `options`: Modern.js 提供的一系列钩子。
29
- - `addMiddleware`: 添加 BFF 中间件的钩子。
30
-
31
- ## 示例
32
-
33
- 使用不同的框架,应添加不同框架的中间件(示例为使用 koa 框架时):
34
-
35
- ```ts title=api/_app.ts
36
- import { hook } from '@modern-js/runtime/koa';
37
-
38
- export default hook(({ addMiddleware }) => {
39
- addMiddleware(async (ctx, next) => {
40
- ctx.req.query.id = 'koa';
41
- await next();
42
- });
43
- });
44
- ```
@@ -1,38 +0,0 @@
1
- ---
2
- title: useContext
3
- ---
4
- # useContext
5
-
6
- 用于在一体化 BFF 函数中获取请求上下文。
7
-
8
- ## 使用姿势
9
-
10
- 根据使用的框架拓展插件,从对应的命名空间中导出:
11
-
12
- ```ts
13
- import { useContext } from '@modern-js/runtime/{namespace}';
14
- ```
15
-
16
- ## 函数签名
17
-
18
- `function useContext(): any`
19
-
20
- ## 示例
21
-
22
- 开发者可以通过 `context` 获取更多的请求信息,例如获取请求 UA(示例为使用 koa 框架时):
23
-
24
- ```ts
25
- import { useContext } from '@modern-js/runtime/koa';
26
-
27
- export async function get() {
28
- const ctx = useContext();
29
- return ctx.req.headers['user-agent'];
30
- }
31
- ```
32
-
33
- :::caution 注意
34
- 只有在一体化 BFF 函数中,你才可以使用 `useContext` API 。
35
-
36
- :::
37
-
38
- 使用不同的运行时框架时,虽然均支持 `useContext` API,但它们的返回值的类型是不同的。
@@ -1,24 +0,0 @@
1
- ---
2
- title: enableHandleWeb
3
- ---
4
-
5
- # bff.enableHandleWeb
6
-
7
- - **类型:** `boolean`
8
- - **默认值:** `false`
9
-
10
- import EnableBFFCaution from "@site-docs/components/enable-bff-caution";
11
-
12
- <EnableBFFCaution />
13
-
14
- 默认情况下,BFF 服务只能处理 BFF API 的请求。
15
-
16
- 当该值设置为 `true` 时,页面请求流量也会经过 BFF,并且 Modern.js 内置的页面渲染的逻辑默认会作为 BFF 服务的最后一个中间件运行。
17
-
18
- ```ts title="modern.config.ts"
19
- export default defineConfig({
20
- bff: {
21
- enableHandleWeb: true,
22
- },
23
- });
24
- ```