mirror of
https://github.com/caprover/caprover
synced 2026-09-23 23:25:38 +00:00
Added capability to change root domain forcefully
This commit is contained in:
@@ -6,6 +6,7 @@ import configstore = require('configstore')
|
||||
import Authenticator = require('../user/Authenticator')
|
||||
import { CaptainEncryptor } from '../utils/Encryptor'
|
||||
import { IBuiltImage } from '../models/IBuiltImage'
|
||||
import Utils from '../utils/Utils'
|
||||
|
||||
const isValidPath = require('is-valid-path')
|
||||
|
||||
@@ -256,15 +257,30 @@ class AppsDataStore {
|
||||
})
|
||||
}
|
||||
|
||||
enableSslForDefaultSubDomain(appName: string) {
|
||||
setSslForDefaultSubDomain(appName: string, isEnabled: boolean) {
|
||||
const self = this
|
||||
|
||||
return this.getAppDefinition(appName).then(function(app) {
|
||||
app.hasDefaultSubDomainSsl = true
|
||||
app.hasDefaultSubDomainSsl = !!isEnabled
|
||||
return self.saveApp(appName, app)
|
||||
})
|
||||
}
|
||||
|
||||
ensureAllAppsSubDomainSslDisabled() {
|
||||
const self = this
|
||||
|
||||
return this.getAppDefinitions().then(function(appDefinitions) {
|
||||
const promises: (() => Promise<void>)[] = []
|
||||
Object.keys(appDefinitions).forEach(appName => {
|
||||
const APP_NAME = appName
|
||||
promises.push(function() {
|
||||
return self.setSslForDefaultSubDomain(APP_NAME, false)
|
||||
})
|
||||
})
|
||||
return Utils.runPromises(promises)
|
||||
})
|
||||
}
|
||||
|
||||
enableCustomDomainSsl(appName: string, customDomain: string) {
|
||||
const self = this
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ router.post('/changerootdomain/', function(req, res, next) {
|
||||
}
|
||||
|
||||
CaptainManager.get()
|
||||
.changeCaptainRootDomain(requestedCustomDomain)
|
||||
.changeCaptainRootDomain(requestedCustomDomain, !!req.body.force)
|
||||
.then(function() {
|
||||
res.send(
|
||||
new BaseApi(ApiStatusCodes.STATUS_OK, 'Root domain changed.')
|
||||
|
||||
@@ -260,7 +260,7 @@ class ServiceManager {
|
||||
.then(function() {
|
||||
return self.dataStore
|
||||
.getAppsDataStore()
|
||||
.enableSslForDefaultSubDomain(appName)
|
||||
.setSslForDefaultSubDomain(appName, true)
|
||||
})
|
||||
.then(function() {
|
||||
return self.reloadLoadBalancer()
|
||||
|
||||
@@ -806,7 +806,7 @@ class CaptainManager {
|
||||
})
|
||||
}
|
||||
|
||||
changeCaptainRootDomain(requestedCustomDomain: string) {
|
||||
changeCaptainRootDomain(requestedCustomDomain: string, force: boolean) {
|
||||
const self = this
|
||||
// Some DNS servers do not allow wild cards. Therefore this line may fail.
|
||||
// We still allow users to specify the domains in their DNS settings individually
|
||||
@@ -827,17 +827,23 @@ class CaptainManager {
|
||||
})
|
||||
.then(function(hasRootSsl) {
|
||||
if (
|
||||
!force &&
|
||||
hasRootSsl &&
|
||||
self.dataStore.getRootDomain() !== requestedCustomDomain
|
||||
) {
|
||||
throw ApiStatusCodes.createError(
|
||||
ApiStatusCodes.STATUS_ERROR_GENERIC,
|
||||
'SSL is enabled for root. Too late to change your mind!'
|
||||
'SSL is enabled for root. You can still force change the root domain, but read docs for consequences!'
|
||||
)
|
||||
}
|
||||
|
||||
return self.dataStore.setCustomDomain(requestedCustomDomain)
|
||||
})
|
||||
.then(function() {
|
||||
return self.dataStore
|
||||
.getAppsDataStore()
|
||||
.ensureAllAppsSubDomainSslDisabled()
|
||||
})
|
||||
.then(function() {
|
||||
return self.reloadLoadBalancer(self.dataStore)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user