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

Allow the user to specify whether they want to use POST or GET for pe… #97

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Options:
|Parameter|type|mandatory|description|
|---------|----|---------|-----------|
|`container`|`boolean`|no|Default true, when false, renders a component without its <oc-component> container|
|`httpMethod`|`string`|no|Default GET, when false, Allows you specify which HTTP method to use. Available options: GET or POST. Note: If you have more than one component, POST is automatically forced.|
|`disableFailoverRendering`|`boolean`|no|Disables the automatic failover rendering in case the registry times-out (in case configuration.registries.clientRendering contains a valid value.) Default false|
|`forwardAcceptLanguageToClient`|`boolean`|no|When not specified in config, defaults to false. When true, when doing client-side requests (normal or failover) appends a custom parameter to the browser's component hrefs so that the framework will ignore the browser's Accept-Language in favour of the query-string value|
|`headers`|`object`|no|An object containing all the headers that must be forwarded to the component|
Expand Down
11 changes: 9 additions & 2 deletions src/get-components-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ module.exports = function(config) {
return cb(serverRenderingFail);
}

const performRequest =
serverRendering.components.length === 1 ? performGet : performPost;
let componentsLength = serverRendering.components.length;
let performRequest = componentsLength === 1 ? performGet : performPost;

const method = (options.httpMethod || '').toLowerCase();
if (method === 'post') {
performRequest = performPost;
} else if (method === 'get') {
performRequest = componentsLength > 1 ? performPost : performGet;
}

performRequest(
serverRenderingEndpoint,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/client-get-component-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('client : get-component-data', () => {
const options = {
parameters: { p1: 'v1', p2: 'v2' },
headers: { 'header-a': 'header-value b' },
httpMethod: 'POST',
timeout: 10
};

Expand Down Expand Up @@ -90,6 +91,7 @@ describe('client : get-component-data', () => {
const options = {
parameters: { p1: 'v1', p2: 'v2' },
headers: { 'header-a': 'header-value b' },
httpMethod: 'GET',
timeout: 10
};

Expand Down