Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete null value in request body #2042

Merged
merged 2 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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