@modern-js/main-doc 0.0.0-nightly-20250513160312 → 0.0.0-nightly-20250515160310

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 (35) hide show
  1. package/docs/en/apis/app/hooks/server/server.mdx +10 -0
  2. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +30 -0
  3. package/docs/en/components/enable-bff.mdx +1 -27
  4. package/docs/en/components/tech-stack-node-framework.mdx +1 -1
  5. package/docs/en/configure/app/plugins.mdx +13 -33
  6. package/docs/en/configure/app/runtime/master-app.mdx +1 -5
  7. package/docs/en/configure/app/runtime/plugins.mdx +58 -0
  8. package/docs/en/guides/advanced-features/bff/extend-server.mdx +33 -82
  9. package/docs/en/guides/advanced-features/bff/frameworks.mdx +12 -68
  10. package/docs/en/guides/advanced-features/bff.mdx +1 -1
  11. package/docs/en/guides/advanced-features/custom-server.mdx +13 -9
  12. package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +2 -0
  13. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  14. package/docs/en/guides/basic-features/html.mdx +3 -3
  15. package/docs/en/plugin/cli-plugins/api.mdx +6 -0
  16. package/docs/en/plugin/runtime-plugins/api.mdx +37 -12
  17. package/docs/zh/apis/app/hooks/server/server.mdx +10 -0
  18. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +31 -0
  19. package/docs/zh/components/enable-bff.mdx +2 -27
  20. package/docs/zh/components/tech-stack-node-framework.mdx +1 -1
  21. package/docs/zh/configure/app/plugins.mdx +3 -24
  22. package/docs/zh/configure/app/runtime/master-app.mdx +1 -5
  23. package/docs/zh/configure/app/runtime/plugins.mdx +58 -0
  24. package/docs/zh/guides/advanced-features/bff/extend-server.mdx +28 -76
  25. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +6 -66
  26. package/docs/zh/guides/advanced-features/custom-server.mdx +12 -8
  27. package/docs/zh/plugin/cli-plugins/api.mdx +6 -0
  28. package/docs/zh/plugin/runtime-plugins/api.mdx +37 -12
  29. package/package.json +2 -2
  30. package/docs/en/apis/app/hooks/api/middleware.mdx +0 -11
  31. package/docs/en/apis/app/runtime/bff/hook.mdx +0 -44
  32. package/docs/en/apis/app/runtime/bff/use-context.mdx +0 -38
  33. package/docs/zh/apis/app/hooks/api/middleware.mdx +0 -11
  34. package/docs/zh/apis/app/runtime/bff/hook.mdx +0 -44
  35. package/docs/zh/apis/app/runtime/bff/use-context.mdx +0 -38
@@ -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,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,但它们的返回值的类型是不同的。