juzhiyuan commented on a change in pull request #1733: URL: https://github.com/apache/apisix-dashboard/pull/1733#discussion_r613137926
########## File path: web/src/components/Plugin/UI/cors.tsx ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import type { FormInstance } from 'antd/es/form'; +import { Button, Col, Form, Input, InputNumber, Row, Select, Switch } from 'antd'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { useIntl } from '@/.umi/plugin-locale/localeExports'; + +type Props = { + form: FormInstance; + ref?: any; +}; + +const FORM_ITEM_LAYOUT = { + labelCol: { + span: 7, + }, + wrapperCol: { + span: 8 + }, +}; + +export const FORM_ITEM_WITHOUT_LABEL = { + wrapperCol: { + sm: { span: 8, offset: 7 }, + }, +}; + +const Cors: React.FC<Props> = ({ form }) => { + const { formatMessage } = useIntl(); + + const HTTPMethods: React.FC = () => ( + <Form.Item + label="allow_methods" + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_methods.tooltip' })} + > + <Row> + <Col span={24}> + <Form.Item + name="allow_methods" + initialValue={["*"]} + > + <Select + mode="multiple" + optionLabelProp="label" + onChange={(value) => { Review comment: ```suggestion onChange={(value: string[]) => { ``` ########## File path: web/src/components/Plugin/UI/cors.tsx ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import type { FormInstance } from 'antd/es/form'; +import { Button, Col, Form, Input, InputNumber, Row, Select, Switch } from 'antd'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { useIntl } from '@/.umi/plugin-locale/localeExports'; + +type Props = { + form: FormInstance; + ref?: any; +}; + +const FORM_ITEM_LAYOUT = { + labelCol: { + span: 7, + }, + wrapperCol: { + span: 8 + }, +}; + +export const FORM_ITEM_WITHOUT_LABEL = { + wrapperCol: { + sm: { span: 8, offset: 7 }, + }, +}; + +const Cors: React.FC<Props> = ({ form }) => { + const { formatMessage } = useIntl(); + + const HTTPMethods: React.FC = () => ( + <Form.Item + label="allow_methods" + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_methods.tooltip' })} + > + <Row> + <Col span={24}> + <Form.Item + name="allow_methods" + initialValue={["*"]} + > + <Select + mode="multiple" + optionLabelProp="label" + onChange={(value) => { + ((value as string[]).join(",")); + if ((value as string[]).includes('*')) { + form.setFieldsValue({ + allow_methods: ['*'], + }); + } + }} + > + {['*', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'CONNECT', 'TRACE'].map((item) => { + return <Select.Option value={item} key={item}>{item}</Select.Option> + })} + </Select> + </Form.Item> + </Col> + </Row> + </Form.Item > + ); + + return ( + <Form + form={form} + {...FORM_ITEM_LAYOUT} + initialValues={{ allow_origins_by_regex: [''] }} Review comment: Why only add initial values for this field here? ########## File path: web/src/components/Plugin/UI/cors.tsx ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import type { FormInstance } from 'antd/es/form'; +import { Button, Col, Form, Input, InputNumber, Row, Select, Switch } from 'antd'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { useIntl } from '@/.umi/plugin-locale/localeExports'; + +type Props = { + form: FormInstance; + ref?: any; +}; + +const FORM_ITEM_LAYOUT = { + labelCol: { + span: 7, + }, + wrapperCol: { + span: 8 + }, +}; + +export const FORM_ITEM_WITHOUT_LABEL = { + wrapperCol: { + sm: { span: 8, offset: 7 }, + }, +}; + +const Cors: React.FC<Props> = ({ form }) => { + const { formatMessage } = useIntl(); + + const HTTPMethods: React.FC = () => ( + <Form.Item + label="allow_methods" + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_methods.tooltip' })} + > + <Row> + <Col span={24}> + <Form.Item + name="allow_methods" + initialValue={["*"]} + > + <Select + mode="multiple" + optionLabelProp="label" + onChange={(value) => { + ((value as string[]).join(",")); + if ((value as string[]).includes('*')) { + form.setFieldsValue({ + allow_methods: ['*'], + }); + } + }} + > + {['*', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'CONNECT', 'TRACE'].map((item) => { + return <Select.Option value={item} key={item}>{item}</Select.Option> + })} + </Select> + </Form.Item> + </Col> + </Row> + </Form.Item > + ); + + return ( + <Form + form={form} + {...FORM_ITEM_LAYOUT} + initialValues={{ allow_origins_by_regex: [''] }} + > + <Form.Item + extra={formatMessage({ id: 'component.pluginForm.cors.allow_origins.extra' })} + name="allow_origins" + label="allow_origins" + initialValue="*" + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_origins.tooltip' })} + > + <Input /> + </Form.Item> + <HTTPMethods /> + + <Form.Item + name="allow_headers" + label="allow_headers" + initialValue="*" + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_headers.tooltip' })} + > + <Input /> + </Form.Item> + <Form.Item + name="expose_headers" + label="expose_headers" + initialValue="*" + tooltip={formatMessage({ id: 'component.pluginForm.cors.expose_headers.tooltip' })} + > + <Input /> + </Form.Item> + <Form.Item + name="max_age" + label="max_age" + initialValue={5} + tooltip={formatMessage({ id: 'component.pluginForm.cors.max_age.tooltip' })} + > + <InputNumber /> + </Form.Item> + <Form.Item + name="allow_credential" + label="allow_credential" + valuePropName="checked" + initialValue={false} + tooltip={formatMessage({ id: 'component.pluginForm.cors.allow_credential.tooltip' })} + > + <Switch /> + </Form.Item> + + <Form.List name={['allow_origins_by_regex']}> Review comment: ```suggestion <Form.List name="allow_origins_by_regex"> ``` ########## File path: web/src/components/Plugin/locales/en-US.ts ########## @@ -21,6 +21,15 @@ export default { 'component.step.select.pluginTemplate.select.option': 'Custom', 'component.plugin.pluginTemplate.tip1': '1. When a route already have plugins field configured, the plugins in the plugin template will be merged into it.', 'component.plugin.pluginTemplate.tip2': '2. The same plugin in the plugin template will override one in the plugins', + // cors + 'component.pluginForm.cors.allow_origins.tooltip': 'Which Origins is allowed to enable CORS, format as:scheme://host:port, for example: https://somehost.com:8081. Multiple origin use , to split. When allow_credential is false, you can use * to indicate allow any origin. you also can allow all any origins forcefully using ** even already enable allow_credential, but it will bring some security risks.', + 'component.pluginForm.cors.allow_origins.extra': 'For example: https://somehost.com:8081', + 'component.pluginForm.cors.allow_methods.tooltip': 'Which Method is allowed to enable CORS, such as: GET, POST etc. Multiple method use , to split. When allow_credential is false, you can use * to indicate allow all any method. You also can allow any method forcefully using ** even already enable allow_credential, but it will bring some security risks.', + 'component.pluginForm.cors.allow_headers.tooltip': 'Which headers are allowed to set in request when access cross-origin resource. Multiple value use , to split. When allow_credential is false, you can use * to indicate allow all request headers. You also can allow any header forcefully using ** even already enable allow_credential, but it will bring some security risks.', + 'component.pluginForm.cors.expose_headers.tooltip': ' Which headers are allowed to set in response when access cross-origin resource. Multiple value use , to split.', Review comment: Space?? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
