Skip to content

Commit

Permalink
Merge pull request #61 from alekseyp/feature/add-always_use_https-cal…
Browse files Browse the repository at this point in the history
…l-support

Add  'Always Use HTTPS' mode
  • Loading branch information
danielpigott authored Jun 29, 2020
2 parents cfffedb + ba6c86a commit 2853ff9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ OPTIONS:
COMMANDS:
add <name> <content>
Add a DNS record. Use -a to activate cf after creation
always-use-https on|off
Toggle Always Use HTTPS mode on/off
devmode on|off
Toggle development mode on/off
disable <name> [content]
Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ function CloudflareCli(options) {
mergeAdditionalParams: true,
formatter: new formatters.MessageFormatter()
},
alwaysUseHttps: {
aliases: ['always-use-https', 'https'],
callback: toggleAlwaysUseHttps,
params: ['mode'],
optionalParams: [],
description: "Redirect all requests with scheme 'http' to 'https'",
formatter: new formatters.MessageFormatter()
},
devmode: {
aliases: ['devmode'],
callback: toggleDevMode,
Expand Down Expand Up @@ -153,6 +161,7 @@ function CloudflareCli(options) {
self.removeRecord = removeRecord;
self.showHelp = showHelp;
self.toggleDevMode = toggleDevMode;
self.toggleAlwaysUseHttps = toggleAlwaysUseHttps;

init(options);

Expand Down Expand Up @@ -229,6 +238,18 @@ function CloudflareCli(options) {
)
}

/**
* Enable/disable Always Use HTTPS mode
* @param options
*/
function toggleAlwaysUseHttps(options) {
return getZone(options.domain).then(function (zone) {
return self.cloudflareClient.setAlwaysUseHttps(zone.id, options.mode);
}).then(function () {
return new Result(['Always Use HTTPS mode changed to ' + options.mode]);
})
}

/**
* Enable proxying/caching for given record
* @param options
Expand Down
11 changes: 11 additions & 0 deletions lib/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function ApiClient(key, email) {
this.editRecord = editRecord;
this.removeRecord = removeRecord;
this.purgeCache = purgeCache;
this.setAlwaysUseHttps = setAlwaysUseHttps;

/**
* Find zones matching the given query
Expand Down Expand Up @@ -79,6 +80,16 @@ function ApiClient(key, email) {
return client.post('/zones/' + zoneId + '/dns_records', options);
}

/**
*
* @param zoneId
* @param enable
* @returns {AxiosPromise<any>}
*/
function setAlwaysUseHttps(zoneId, enable) {
return client.patch(`/zones/${zoneId}/settings/always_use_https`, {value: enable});
}

/**
*
* @param zoneId
Expand Down

0 comments on commit 2853ff9

Please sign in to comment.