diff --git a/CHANGELOG.md b/CHANGELOG.md index 812cf4d350..bb5dcabaf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - [#2616](https://github.com/poanetwork/blockscout/pull/2616) - deduplicate coin history records by delta - [#2613](https://github.com/poanetwork/blockscout/pull/2613) - fix getminedblocks rpc endpoint - [#2592](https://github.com/poanetwork/blockscout/pull/2592) - process new metadata format for whisper +- [#2591](https://github.com/poanetwork/blockscout/pull/2591) - Fix url error in API page - [#2572](https://github.com/poanetwork/blockscout/pull/2572) - Ease non-critical css - [#2570](https://github.com/poanetwork/blockscout/pull/2570) - Network icons preload - [#2569](https://github.com/poanetwork/blockscout/pull/2569) - do not fetch emission rewards for transactions csv exporter diff --git a/apps/block_scout_web/assets/js/lib/try_api.js b/apps/block_scout_web/assets/js/lib/try_api.js index c0eb8cd5e3..6c33779f30 100644 --- a/apps/block_scout_web/assets/js/lib/try_api.js +++ b/apps/block_scout_web/assets/js/lib/try_api.js @@ -55,6 +55,10 @@ function handleSuccess (query, xhr, clickedButton) { clickedButton.prop('disabled', false) } +function dropDomain (url) { + return new URL(url).pathname +} + // Show 'Try it out' UI for a module/action. $('button[data-selector*="btn-try-api"]').click(event => { const clickedButton = $(event.target) @@ -124,7 +128,7 @@ $('button[data-try-api-ui-button-type="execute"]').click(event => { } $.ajax({ - url: `/api${query}`, + url: dropDomain(composeRequestUrl(query)), success: (_data, _status, xhr) => { handleSuccess(query, xhr, clickedButton) }, diff --git a/apps/block_scout_web/assets/js/lib/try_eth_api.js b/apps/block_scout_web/assets/js/lib/try_eth_api.js index a3dd7b6f4e..30299431be 100644 --- a/apps/block_scout_web/assets/js/lib/try_eth_api.js +++ b/apps/block_scout_web/assets/js/lib/try_eth_api.js @@ -1,7 +1,8 @@ import $ from 'jquery' function composeCurlCommand (data) { - return `curl -H "content-type: application/json" -X POST --data '${JSON.stringify(data)}'` + const url = $('[data-endpoint-url]').attr('data-endpoint-url') + return `curl -H "content-type: application/json" -X POST --data '${JSON.stringify(data)}' ${url}` } function handleResponse (data, xhr, clickedButton) { @@ -43,6 +44,10 @@ function parseInput (input) { } } +function dropDomain (url) { + return new URL(url).pathname +} + $('button[data-try-eth-api-ui-button-type="execute"]').click(event => { const clickedButton = $(event.target) const module = clickedButton.attr('data-module') @@ -50,7 +55,6 @@ $('button[data-try-eth-api-ui-button-type="execute"]').click(event => { const inputs = $(`input[data-selector="${module}-${action}-try-api-ui"]`) const params = $.map(inputs, parseInput) const formData = wrapJsonRpc(action, params) - console.log(formData) const loadingText = ' Loading...' clickedButton.prop('disabled', true) @@ -60,8 +64,10 @@ $('button[data-try-eth-api-ui-button-type="execute"]').click(event => { clickedButton.html(loadingText) } + const url = $('[data-endpoint-url]').attr('data-endpoint-url') + $.ajax({ - url: '/api/eth_rpc', + url: dropDomain(url), type: 'POST', data: JSON.stringify(formData), dataType: 'json', diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex index 7f342b4a16..f464533c7e 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex @@ -4,9 +4,9 @@
<%= raw @info.notes %>
- curl -X POST --data '{"id":0,"jsonrpc":"2.0","method": "<%= @action %>", params: []}' + curl -X POST --data '{"id":0,"jsonrpc":"2.0","method": "<%= @action %>", "params": []}'