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

Improve copy to curl #546

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,12 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http',
if (path.substring(0, 1) !== '/') {
path = '/' + path;
}
var host = $scope.host;

// cut off trailing slash in hostname to not produce double-slashes
if (host.endsWith('/')) {
host = host.substring(0, host.length - 1);
}

var matchesAPI = function(path, api) {
return path.indexOf(api) === (path.length - api.length);
Expand All @@ -1739,10 +1745,19 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http',

var curl = 'curl';
curl += ' -H \'Content-type: ' + contentType + '\'';
curl += ' -X' + method + ' \'' + $scope.host + path + '\'';
curl += ' -X' + method + ' \'' + host + path + '\'';

// add body for POST and PUT
if (['POST', 'PUT'].indexOf(method) >= 0) {
curl += ' -d \'' + body + '\'';
}

// GET can have body as well, e.g. the Elasticsearch Query
if (['GET'].indexOf(method) >= 0 &&
typeof body !== 'undefined' && body !== '' && body.trim() !== '{}') {
curl += ' -d \'' + body + '\'';
}

ClipboardService.copy(
curl,
function() {
Expand Down