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