Skip to content

Commit

Permalink
fix: delete null value in request body (#2042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baoyuantop authored Aug 7, 2021
1 parent 61e1b76 commit 5198854
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/cypress/integration/route/search-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ context('Create and Search Route', () => {
});
});

cy.contains('Next').click();
cy.contains('button', 'Next').should('not.be.disabled').click();
cy.get(selector.nodes_0_host).type(data.host2, {
timeout,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ context('Create and Delete Upstream', () => {
cy.get(selector.nodes_0_host).type(data.ip1);
cy.get(selector.nodes_0_port).clear().type('7000');
cy.get(selector.nodes_0_weight).clear().type(1);
cy.get('#custom_checks_active').click();
cy.get('#checks_active_port').clear();
cy.contains('Next').click();
cy.get(selector.input).should('be.disabled');
cy.contains('Submit').click();
Expand Down
15 changes: 15 additions & 0 deletions web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React from 'react';
import { history } from 'umi';
import type { RequestConfig } from 'umi';
import type { Settings as LayoutSettings } from '@ant-design/pro-layout';
import { isPlainObject } from 'lodash';

import RightContent from '@/components/RightContent';
import Footer from '@/components/Footer';
Expand Down Expand Up @@ -55,13 +56,27 @@ export const layout = ({ initialState }: { initialState: { settings?: LayoutSett
};
};

/* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["obj"] }] */
const nullValueFilter = (obj: Record<string, any>) => {
Object.entries(obj).forEach(([key, value]) => {
if (isPlainObject(value)) {
nullValueFilter(value);
} else if ([null, undefined].includes(value)) {
delete obj[key];
}
});
};

export const request: RequestConfig = {
prefix: '/apisix/admin',
errorHandler,
credentials: 'same-origin',
requestInterceptors: [
(url, options) => {
const newOptions = { ...options };
if (newOptions.data) {
nullValueFilter(newOptions.data);
}
newOptions.headers = {
...options.headers,
Authorization: localStorage.getItem('token') || '',
Expand Down
1 change: 1 addition & 0 deletions web/src/components/Upstream/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
'component.upstream.fields.checks.active.http_path': 'HTTP Path',
'component.upstream.fields.checks.active.http_path.tooltip':
'The path that should be used when issuing the HTTP GET request to the target. The default value is /.',
'component.upstream.fields.checks.active.http_path.placeholder': 'Please enter HTTP path',

'component.upstream.fields.checks.active.https_verify_certificate': 'Verify HTTPs Certificate',
'component.upstream.fields.checks.active.https_verify_certificate.tooltip':
Expand Down

0 comments on commit 5198854

Please sign in to comment.