Skip to content

Commit

Permalink
append http protocol to url if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Aug 12, 2023
1 parent 1904133 commit 1b7710c
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ export class UrlBoxComponent {
methods = HTTP_VERBS;

setApiUrl() {
this.urlChange.emit(this.apiUrl.trim());
this.urlChange.emit(this.sanitizeUrl(this.apiUrl));
}

setVerb(verb: string) {
this.httpVerbChange.emit(verb);
}

sanitizeUrl(url: string) {
// trim the url and remove any spaces
// add http protocol if missing
url = url.trim();
if (!url.match(/^[a-zA-Z]+:\/\//)) {
url = 'http://' + url;
}

return url;
}

queryOperationTrackBy(index: number, operation: OperationDefinitionNode) {
return operation.name && operation.name.value;
}
Expand Down

0 comments on commit 1b7710c

Please sign in to comment.