You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/07/03 07:23:36 UTC
[GitHub] liubao68 closed pull request #9: 增加跨域资源共享(CORS)机制的说明
liubao68 closed pull request #9: 增加跨域资源共享(CORS)机制的说明
URL: https://github.com/apache/incubator-servicecomb-docs/pull/9
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/java-chassis-reference/zh_CN/SUMMARY.md b/java-chassis-reference/zh_CN/SUMMARY.md
index 0b89792..53c5a93 100644
--- a/java-chassis-reference/zh_CN/SUMMARY.md
+++ b/java-chassis-reference/zh_CN/SUMMARY.md
@@ -56,6 +56,7 @@
* [定制序列化和反序列化方法](general-development/secret-field.md)
* [使用Context传递控制消息](general-development/context.md)
* [返回值序列化扩展](general-development/produceprocess.md)
+ * [CORS机制](general-development/CORS.md)
* [服务能力开放](edge/open-service.md)
* [使用Edge Service做边缘服务](edge/by-servicecomb-sdk.md)
* [使用confd和Nginx做边缘服务](edge/nginx.md)
diff --git a/java-chassis-reference/zh_CN/general-development/CORS.md b/java-chassis-reference/zh_CN/general-development/CORS.md
new file mode 100644
index 0000000..5f9e677
--- /dev/null
+++ b/java-chassis-reference/zh_CN/general-development/CORS.md
@@ -0,0 +1,38 @@
+# CORS机制
+
+## 概念阐述
+
+跨域资源共享(CORS, Cross-Origin Resource Sharing)允许Web服务器进行跨域访问控制,使浏览器可以更安全地进行跨域数据传输。
+
+## 场景描述
+
+当用户需要从浏览器上跨域发送REST请求时就有可能要用到CORS机制,接收跨域请求的微服务需要开启CORS支持。
+
+## 配置说明
+
+CORS功能在microservice.yaml文件中配置,配置项见下表所述。
+
+| 配置项 | 默认值 | 取值范围 | 是否必选 | 含义 | 注意 |
+| :--- | :--- | :--- | :--- | :--- | :--- |
+| servicecomb.cors.enabled | `false` | `true`/`false` | 否 | 是否开启CORS功能 | - |
+| servicecomb.cors.origin | `*` | - | 否 | Access-Control-Allow-Origin | - |
+| servicecomb.cors.allowCredentials | `false` | `true`/`false` | 否 | Access-Control-Allow-Credentials | 根据CORS标准,当Access-Control-Allow-Credentials设置为`true`时,Access-Control-Allow-Origin不可设置为"*",否则将会抛出异常 |
+| servicecomb.cors.allowedHeader | 无 | - | 否 | Access-Control-Allow-Headers | 多个值使用逗号分隔 |
+| servicecomb.cors.allowedMethod | 无 | - | 否 | Access-Control-Allow-Methods | 多个值使用逗号分隔 |
+| servicecomb.cors.exposedHeader | 无 | - | 否 | Access-Control-Expose-Headers | 多个值使用逗号分隔 |
+| servicecomb.cors.maxAge | 无 | (0,2147483647],整型 | 否 | Access-Control-Max-Age | 单位是秒,如果用户不配置此项,则CORS应答中没有Access-Control-Max-Age |
+
+
+## 示例代码
+
+```yaml
+servicecomb:
+ cors:
+ enabled: true
+ origin: "*"
+ allowCredentials: false
+ allowedHeaders: Header-abc, Header-def
+ allowdedMethod: GET,PUT,DELETE,POST
+ exposedHeaders: Header-abc, Header-def
+ maxAge: 3600
+```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services