@modern-js/main-doc 2.48.6 → 2.49.0
Sign up to get free protection for your applications and to get access to all the features.
- package/docs/en/guides/basic-features/proxy.mdx +0 -22
- package/docs/en/guides/troubleshooting/dependencies.mdx +1 -1
- package/docs/zh/guides/basic-features/proxy.mdx +0 -22
- package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
- package/package.json +5 -5
- package/docs/en/configure/app/bff/proxy.mdx +0 -65
- package/docs/en/guides/advanced-features/bff/bff-proxy.mdx +0 -30
- package/docs/zh/configure/app/bff/proxy.mdx +0 -64
- package/docs/zh/guides/advanced-features/bff/bff-proxy.mdx +0 -30
@@ -36,25 +36,3 @@ For more detail, see [http-proxy-middleware](https://github.com/chimurai/http-pr
|
|
36
36
|
import GlobalProxy from "@site-docs-en/components/global-proxy"
|
37
37
|
|
38
38
|
<GlobalProxy />
|
39
|
-
|
40
|
-
## BFF Proxy
|
41
|
-
|
42
|
-
By configuring [`bff.proxy`](/configure/app/bff/proxy), BFF API requests can be proxied to a specified service. Unlike the other proxy methods above, it can be used in the production environment:
|
43
|
-
|
44
|
-
```ts title="modern.config.ts"
|
45
|
-
export default defineConfig({
|
46
|
-
bff: {
|
47
|
-
proxy: {
|
48
|
-
'/api/v1': 'https://cnodejs.org',
|
49
|
-
},
|
50
|
-
},
|
51
|
-
});
|
52
|
-
```
|
53
|
-
|
54
|
-
For example, when using BFF function in the code, the final request `http://localhost:8080/api/v1/topics` will be automatically proxied to `https://cnodejs.org/api/v1/topics`:
|
55
|
-
|
56
|
-
```js
|
57
|
-
import getTopics from '@api/v1/topics';
|
58
|
-
|
59
|
-
getTopics();
|
60
|
-
```
|
@@ -43,7 +43,7 @@ If you encounter the following error message during dependency installation, it
|
|
43
43
|
```bash
|
44
44
|
The engine "node" is incompatible with this module.
|
45
45
|
|
46
|
-
Expected version ">=
|
46
|
+
Expected version ">=16.2.0". Got "12.20.1"
|
47
47
|
```
|
48
48
|
|
49
49
|
When using Modern.js, it is recommended to use the latest version of [Node.js 18.x](https://nodejs.org/download/release/latest-v18.x/).
|
@@ -37,25 +37,3 @@ export default defineConfig({
|
|
37
37
|
import GlobalProxy from "@site-docs/components/global-proxy"
|
38
38
|
|
39
39
|
<GlobalProxy />
|
40
|
-
|
41
|
-
## BFF 代理
|
42
|
-
|
43
|
-
通过配置 [`bff.proxy`](/configure/app/bff/proxy) 可以代理 BFF API 请求到指定的服务上,上述两种代理不同,它同样可以用在生产环境:
|
44
|
-
|
45
|
-
```ts title="modern.config.ts"
|
46
|
-
export default defineConfig({
|
47
|
-
bff: {
|
48
|
-
proxy: {
|
49
|
-
'/api/v1': 'https://cnodejs.org',
|
50
|
-
},
|
51
|
-
},
|
52
|
-
});
|
53
|
-
```
|
54
|
-
|
55
|
-
例如代码中使用一体化 BFF 调用时,最终请求 `http://localhost:8080/api/v1/topics` 会自动代理到 `https://cnodejs.org/api/v1/topics`:
|
56
|
-
|
57
|
-
```js
|
58
|
-
import getTopics from '@api/v1/topics';
|
59
|
-
|
60
|
-
getTopics();
|
61
|
-
```
|
@@ -43,7 +43,7 @@ devDependencies:
|
|
43
43
|
```bash
|
44
44
|
The engine "node" is incompatible with this module.
|
45
45
|
|
46
|
-
Expected version ">=
|
46
|
+
Expected version ">=16.2.0". Got "12.20.1"
|
47
47
|
```
|
48
48
|
|
49
49
|
使用 Modern.js 时,建议使用 [Node.js 18.x](https://nodejs.org/download/release/latest-v18.x/) 的最新版本。
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.49.0",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "2.
|
25
|
+
"@modern-js/sandpack-react": "2.49.0"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "^2.
|
28
|
+
"@modern-js/builder-doc": "^2.49.0"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -39,8 +39,8 @@
|
|
39
39
|
"@rspress/shared": "1.16.0",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "9.0.13",
|
42
|
-
"@modern-js/builder-doc": "2.
|
43
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.
|
42
|
+
"@modern-js/builder-doc": "2.49.0",
|
43
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.49.0"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|
@@ -1,65 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_label: proxy
|
3
|
-
---
|
4
|
-
|
5
|
-
# bff.proxy
|
6
|
-
|
7
|
-
- **Type:** `Record<string, string>`
|
8
|
-
- **Default:** `{}`
|
9
|
-
|
10
|
-
import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
11
|
-
|
12
|
-
<EnableBFFCaution />
|
13
|
-
|
14
|
-
With simple configuration, Modern.js can automatically proxy requests sent to the BFF server to the specified service.
|
15
|
-
|
16
|
-
Add the following configuration to `modern.server-runtime.config.js` to enable proxy:
|
17
|
-
|
18
|
-
```ts title="modern.server-runtime.config.ts"
|
19
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
20
|
-
export default defineConfig({
|
21
|
-
bff: {
|
22
|
-
proxy: {
|
23
|
-
'/api': 'https://cnodejs.org',
|
24
|
-
},
|
25
|
-
},
|
26
|
-
});
|
27
|
-
```
|
28
|
-
|
29
|
-
Assuming the address of Modern.js BFF server is `localhost:8080`, all requests starting with `api` will be proxied to `https://cnodejs.org`, for example, the request to `localhost:8080/api/v1/topics` will be proxied to `https://cnodejs.org/api/v1/topics`.
|
30
|
-
|
31
|
-
import BFFProxyPathRewrite from "@site-docs-en/components/bff-proxy-path-rewrite";
|
32
|
-
|
33
|
-
<BFFProxyPathRewrite />
|
34
|
-
|
35
|
-
Unlike [dev.proxy](/configure/app/dev/proxy), the proxy here only applies to requests entering the BFF/API service; at the same time, this configuration can not only be used in the development environment, but also proxies corresponding requests in the production environment.
|
36
|
-
|
37
|
-
import BFFProxyPrinciple from "@site-docs-en/components/bff-proxy-principle";
|
38
|
-
|
39
|
-
<BFFProxyPrinciple />
|
40
|
-
|
41
|
-
## Common Usage
|
42
|
-
|
43
|
-
### Solving Cross-Domain Issues for APIs
|
44
|
-
|
45
|
-
During project development, cross-domain issues are often encountered because web pages and API services are not deployed under the same domain name.
|
46
|
-
There are many ways to solve cross-domain issues, and here we can easily solve them using `bff.proxy`.
|
47
|
-
|
48
|
-
:::info
|
49
|
-
Under BFF proxy mode, if you don't need to write BFF code, the API directory can be deleted; BFF proxy will still be enabled.
|
50
|
-
|
51
|
-
:::
|
52
|
-
|
53
|
-
As shown below, the following configuration in `modern.server-runtime.config.ts` will proxy all web page requests starting with `/api` to a service on another domain with the same domain.
|
54
|
-
|
55
|
-
```ts title="modern.server-runtime.config.ts"
|
56
|
-
export default defineServerConfig({
|
57
|
-
bff: {
|
58
|
-
proxy: {
|
59
|
-
'/api': 'https://cnodejs.org',
|
60
|
-
},
|
61
|
-
},
|
62
|
-
};
|
63
|
-
```
|
64
|
-
|
65
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 5
|
3
|
-
title: Use Proxy
|
4
|
-
---
|
5
|
-
# Use Proxy
|
6
|
-
|
7
|
-
By configuring the BFF proxy, API requests can be forwarded without manual coding
|
8
|
-
|
9
|
-
:::caution
|
10
|
-
Using a BFF proxy ensures that requests can enter the BFF handler. (eg the request path must contain a bff prefix)
|
11
|
-
|
12
|
-
:::
|
13
|
-
|
14
|
-
Writing the following BFF proxy configuration in the `modern.server-runtime.config.js` file will proxy requests sent to `http://localhost:8080/api/v1/topics` to `https://cnodejs.org/api/v1/topics`.
|
15
|
-
|
16
|
-
```js title="modern.server-runtime.config.js"
|
17
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
18
|
-
export default defineConfig({
|
19
|
-
bff: {
|
20
|
-
proxy: {
|
21
|
-
'/api/v1/topics': 'https://cnodejs.org',
|
22
|
-
},
|
23
|
-
},
|
24
|
-
};
|
25
|
-
```
|
26
|
-
|
27
|
-
:::note
|
28
|
-
For more detail, see [bff.proxy](/configure/app/bff/proxy). For more proxy info, see [Proxy](/guides/basic-features/proxy).
|
29
|
-
|
30
|
-
:::
|
@@ -1,64 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_label: proxy
|
3
|
-
---
|
4
|
-
|
5
|
-
# bff.proxy
|
6
|
-
|
7
|
-
- **类型:** `Record<string, string>`
|
8
|
-
- **默认值:** `{}`
|
9
|
-
|
10
|
-
import EnableBFFCaution from "@site-docs/components/enable-bff-caution";
|
11
|
-
|
12
|
-
<EnableBFFCaution />
|
13
|
-
|
14
|
-
通过简单配置,Modern.js 可以将发送给 BFF server 的请求,自动代理到指定的服务上。
|
15
|
-
|
16
|
-
在 `modern.server-runtime.config.js` 中加入以下配置;即可开启代理:
|
17
|
-
|
18
|
-
```js title="modern.server-runtime.config.js"
|
19
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
20
|
-
export default defineConfig({
|
21
|
-
bff: {
|
22
|
-
proxy: {
|
23
|
-
'/api': 'https://cnodejs.org',
|
24
|
-
},
|
25
|
-
},
|
26
|
-
});
|
27
|
-
```
|
28
|
-
|
29
|
-
假设 Modern.js BFF server 的地址是 `localhost:8080`,所有以 `api` 开头的请求都会被代理到 `https://cnodejs.org`,如 `localhost:8080/api/v1/topics` 的请求会被代理到 `https://cnodejs.org/api/v1/topics`。
|
30
|
-
|
31
|
-
import BFFProxyPathRewrite from "@site-docs/components/bff-proxy-path-rewrite";
|
32
|
-
|
33
|
-
<BFFProxyPathRewrite />
|
34
|
-
|
35
|
-
与 [dev.proxy](/configure/app/dev/proxy) 不同,本节所介绍的代理只作用于进入 BFF/API 服务的请求;同时,这一配置不但可以在开发环境中使用,在生产环境中也会代理相应的请求。
|
36
|
-
|
37
|
-
import BFFProxyPrinciple from "@site-docs/components/bff-proxy-principle";
|
38
|
-
|
39
|
-
<BFFProxyPrinciple />
|
40
|
-
|
41
|
-
## 常见用法
|
42
|
-
|
43
|
-
### 解决接口跨域问题
|
44
|
-
|
45
|
-
在项目开发过程中,因为 web 页面和接口服务不是部署在同一个域名下,常常会遇到跨域问题。
|
46
|
-
解决跨域问题的方式有很多,在这里我们使用 `bff.proxy` 可以轻松解决跨域问题。
|
47
|
-
|
48
|
-
:::info
|
49
|
-
BFF proxy 模式下,如果不需要写 BFF 的接口, API 目录可以删除;此时 BFF proxy 仍会开启。
|
50
|
-
|
51
|
-
:::
|
52
|
-
|
53
|
-
如下所示,在 `modern.server-runtime.config.ts` 中,写入如下配置;我们将所有 web 页面发送到同域的以 `/api` 开头的请求代理到另一个域名的服务上。
|
54
|
-
|
55
|
-
```ts title="modern.server-runtime.config.ts"
|
56
|
-
export default defineServerConfig({
|
57
|
-
bff: {
|
58
|
-
proxy: {
|
59
|
-
'/api': 'https://cnodejs.org',
|
60
|
-
},
|
61
|
-
},
|
62
|
-
};
|
63
|
-
```
|
64
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 5
|
3
|
-
title: 使用 BFF 代理
|
4
|
-
---
|
5
|
-
# 使用 BFF 代理
|
6
|
-
|
7
|
-
通过配置 BFF 代理,无需手动写码,即可对 API 请求进行转发。
|
8
|
-
|
9
|
-
:::caution
|
10
|
-
使用 BFF 代理需确保请求能进入 BFF handler。(例如请求路径必须包含 bff prefix)
|
11
|
-
|
12
|
-
:::
|
13
|
-
|
14
|
-
在 `modern.server-runtime.config.js` 文件中编写以下 BFF 代理配置,会将发送到 `http://localhost:8080/api/v1/topics` 的请求代理到 `https://cnodejs.org/api/v1/topics`。
|
15
|
-
|
16
|
-
```js title="modern.server-runtime.config.js"
|
17
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
18
|
-
export default defineConfig({
|
19
|
-
bff: {
|
20
|
-
proxy: {
|
21
|
-
'/api/v1/topics': 'https://cnodejs.org',
|
22
|
-
},
|
23
|
-
},
|
24
|
-
};
|
25
|
-
```
|
26
|
-
|
27
|
-
:::note
|
28
|
-
详细 API 请查看 [BFF 代理](/configure/app/bff/proxy)。更多 Modern.js 代理的能力可查看[调试代理](/guides/basic-features/proxy)。
|
29
|
-
|
30
|
-
:::
|