@modern-js/main-doc 0.0.0-next-1686556197370 → 0.0.0-next-1686559924703
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/CHANGELOG.md +3 -3
- package/docs/en/components/bff-proxy-path-rewrite.mdx +16 -0
- package/docs/en/components/bff-proxy-principle.mdx +1 -0
- package/docs/en/configure/app/bff/proxy.mdx +4 -19
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +16 -0
- package/docs/zh/components/bff-proxy-principle.mdx +1 -0
- package/docs/zh/configure/app/bff/proxy.mdx +4 -18
- package/package.json +5 -5
- package/docs/en/components/bff-proxy-other-config.mdx +0 -0
- package/docs/zh/components/bff-proxy-other-config.mdx +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @modern-js/main-doc
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-1686559924703
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
docs(main): 更新 HTML 模板文档
|
|
26
26
|
|
|
27
|
-
-
|
|
27
|
+
- d67b665c9: docs(main): update bff config doc
|
|
28
28
|
|
|
29
29
|
docs(main): 更新 BFF 配置文档
|
|
30
30
|
|
|
31
31
|
- Updated dependencies [7e6fb5fc1]
|
|
32
|
-
- @modern-js/builder-doc@0.0.0-next-
|
|
32
|
+
- @modern-js/builder-doc@0.0.0-next-1686559924703
|
|
33
33
|
|
|
34
34
|
## 2.22.1
|
|
35
35
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Path rewriting can also be performed here, such as proxying the request sent to `localhost:8080/api/topics` to `https://cnodejs.org/api/v1/topics`.
|
|
2
|
+
|
|
3
|
+
```js title="modern.server-runtime.config.js"
|
|
4
|
+
import { defineConfig } from '@modern-js/app-tools/server';
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
bff: {
|
|
7
|
+
proxy: {
|
|
8
|
+
'/api': {
|
|
9
|
+
target: 'https://cnodejs.org',
|
|
10
|
+
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
|
11
|
+
changeOrigin: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
BFF Proxy uses the powerful [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware). For more advanced usage, please refer to its [documentation](https://github.com/chimurai/http-proxy-middleware#options).
|
|
@@ -13,8 +13,6 @@ import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
|
|
13
13
|
|
|
14
14
|
With simple configuration, Modern.js can automatically proxy requests sent to the BFF server to the specified service.
|
|
15
15
|
|
|
16
|
-
BFF Proxy uses the powerful [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware). For more advanced usage, please refer to its [documentation](https://github.com/chimurai/http-proxy-middleware#options).
|
|
17
|
-
|
|
18
16
|
Add the following configuration to `modern.server-runtime.config.js` to enable proxy:
|
|
19
17
|
|
|
20
18
|
```ts title="modern.server-runtime.config.ts"
|
|
@@ -30,28 +28,15 @@ export default defineConfig({
|
|
|
30
28
|
|
|
31
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`.
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
import BFFProxyPathRewrite from "@site-docs/components/bff-proxy-path-rewrite";
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
|
37
|
-
export default defineConfig({
|
|
38
|
-
bff: {
|
|
39
|
-
proxy: {
|
|
40
|
-
'/api': {
|
|
41
|
-
target: 'https://cnodejs.org',
|
|
42
|
-
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
|
43
|
-
changeOrigin: true,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
```
|
|
33
|
+
<BFFProxyPathRewrite />
|
|
49
34
|
|
|
50
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.
|
|
51
36
|
|
|
52
|
-
import
|
|
37
|
+
import BFFProxyPrinciple from "@site-docs/components/bff-proxy-principle";
|
|
53
38
|
|
|
54
|
-
<
|
|
39
|
+
<BFFProxyPrinciple />
|
|
55
40
|
|
|
56
41
|
## Common Usage
|
|
57
42
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
这里还可以进行路径重写,如将发送到 `localhost:8080/api/topics` 的请求代理到 `https://cnodejs.org/api/v1/topics`。
|
|
2
|
+
|
|
3
|
+
```ts title="modern.server-runtime.config.ts"
|
|
4
|
+
import { defineConfig } from '@modern-js/app-tools/server';
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
bff: {
|
|
7
|
+
proxy: {
|
|
8
|
+
'/api': {
|
|
9
|
+
target: 'https://cnodejs.org',
|
|
10
|
+
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
|
11
|
+
changeOrigin: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
BFF Proxy 使用了强大的 [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware),如果需要更多高级的用法, 可以查看它的[文档](https://github.com/chimurai/http-proxy-middleware#options)。
|
|
@@ -12,7 +12,6 @@ import EnableBFFCaution from "@site-docs/components/enable-bff-caution";
|
|
|
12
12
|
<EnableBFFCaution />
|
|
13
13
|
|
|
14
14
|
通过简单配置,Modern.js 可以将发送给 BFF server 的请求,自动代理到指定的服务上。
|
|
15
|
-
BFF Proxy 使用了强大的 [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware),如果需要更多高级的用法, 可以查看它的[文档](https://github.com/chimurai/http-proxy-middleware#options)。
|
|
16
15
|
|
|
17
16
|
在 `modern.server-runtime.config.js` 中加入以下配置;即可开启代理:
|
|
18
17
|
|
|
@@ -29,28 +28,15 @@ export default defineConfig({
|
|
|
29
28
|
|
|
30
29
|
假设 Modern.js BFF server 的地址是 `localhost:8080`,所有以 `api` 开头的请求都会被代理到 `https://cnodejs.org`,如 `localhost:8080/api/v1/topics` 的请求会被代理到 `https://cnodejs.org/api/v1/topics`。
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
import BFFProxyPathRewrite from "@site-docs/components/bff-proxy-path-rewrite";
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
|
36
|
-
export default defineConfig({
|
|
37
|
-
bff: {
|
|
38
|
-
proxy: {
|
|
39
|
-
'/api': {
|
|
40
|
-
target: 'https://cnodejs.org',
|
|
41
|
-
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
|
42
|
-
changeOrigin: true,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
```
|
|
33
|
+
<BFFProxyPathRewrite />
|
|
48
34
|
|
|
49
35
|
与 [dev.proxy](/configure/app/dev/proxy) 不同,本节所介绍的代理只作用于进入 BFF/API 服务的请求;同时,这一配置不但可以在开发环境中使用,在生产环境中也会代理相应的请求。
|
|
50
36
|
|
|
51
|
-
import
|
|
37
|
+
import BFFProxyPrinciple from "@site-docs/components/bff-proxy-principle";
|
|
52
38
|
|
|
53
|
-
<
|
|
39
|
+
<BFFProxyPrinciple />
|
|
54
40
|
|
|
55
41
|
## 常见用法
|
|
56
42
|
|
package/package.json
CHANGED
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-next-
|
|
18
|
+
"version": "0.0.0-next-1686559924703",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
|
21
21
|
"access": "public",
|
|
22
22
|
"provenance": true
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@modern-js/builder-doc": "0.0.0-next-
|
|
25
|
+
"@modern-js/builder-doc": "0.0.0-next-1686559924703"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"classnames": "^2",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"fs-extra": "^10",
|
|
35
35
|
"@types/node": "^16",
|
|
36
36
|
"@types/fs-extra": "^9",
|
|
37
|
-
"@modern-js/builder-doc": "0.0.0-next-
|
|
38
|
-
"@modern-js/doc-tools": "0.0.0-next-
|
|
39
|
-
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-
|
|
37
|
+
"@modern-js/builder-doc": "0.0.0-next-1686559924703",
|
|
38
|
+
"@modern-js/doc-tools": "0.0.0-next-1686559924703",
|
|
39
|
+
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-1686559924703"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "modern dev",
|
|
File without changes
|
|
File without changes
|