Skip to content

Commit d1ce6d4

Browse files
Handle URL params gently (#370)
Previously url variable has strictly provided "https" protocol, which totally broke feed if "https" was provided in endpoint variable. Add new function based on regex to handle both types with or without protocol.
1 parent ef61e6c commit d1ce6d4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

action/lib/common.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ function triggerComponents(triggerName) {
2626
};
2727
}
2828

29+
function addHTTPS(url) {
30+
if (!/^https?\:\/\//.test(url)) {
31+
url = "https://" + url;
32+
}
33+
return url;
34+
}
35+
2936
function getTriggerURL(endpoint, triggerName) {
30-
var massagedAPIHost = endpoint.replace(/https?:\/\/(.*)/, "$1");
37+
var apiHost = addHTTPS(endpoint);
3138

3239
var components = triggerComponents(triggerName);
3340
var namespace = components.namespace;
3441
var trigger = components.triggerName;
3542

36-
var url = `https://${massagedAPIHost}/api/v1/namespaces/${encodeURIComponent(namespace)}/triggers/${encodeURIComponent(trigger)}`;
43+
var url = `${apiHost}/api/v1/namespaces/${encodeURIComponent(namespace)}/triggers/${encodeURIComponent(trigger)}`;
3744

3845
return url;
3946
}
@@ -98,7 +105,9 @@ function massageParamsForWeb(rawParams) {
98105
}
99106

100107
function getWebActionURL(endpoint, actionName) {
101-
return `https://${endpoint}/api/v1/web/whisk.system/messagingWeb/${actionName}.http`;
108+
var apiHost = addHTTPS(endpoint);
109+
110+
return `${apiHost}/api/v1/web/whisk.system/messagingWeb/${actionName}`;
102111
}
103112

104113
function createTrigger(endpoint, params, actionName) {

0 commit comments

Comments
 (0)