diff --git a/src/datastore/AppsDataStore.ts b/src/datastore/AppsDataStore.ts index b900e0c..e6422c1 100644 --- a/src/datastore/AppsDataStore.ts +++ b/src/datastore/AppsDataStore.ts @@ -562,7 +562,8 @@ class AppsDataStore { repoInfo: RepoInfo, authenticator: Authenticator, customNginxConfig: string, - preDeployFunction: string + preDeployFunction: string, + websocketSupport: boolean ) { const self = this let appObj: IAppDef @@ -630,6 +631,7 @@ class AppsDataStore { appObj.notExposeAsWebApp = !!notExposeAsWebApp appObj.containerHttpPort = containerHttpPort appObj.forceSsl = !!forceSsl + appObj.websocketSupport = !!websocketSupport appObj.nodeId = nodeId appObj.customNginxConfig = customNginxConfig appObj.preDeployFunction = preDeployFunction @@ -800,6 +802,7 @@ class AppsDataStore { customDomain: [], hasDefaultSubDomainSsl: false, forceSsl: false, + websocketSupport: false } resolve(defaultAppDefinition) diff --git a/src/models/AppDefinition.ts b/src/models/AppDefinition.ts index 573a666..b394e01 100644 --- a/src/models/AppDefinition.ts +++ b/src/models/AppDefinition.ts @@ -57,6 +57,7 @@ interface IAppDefinitionBase { containerHttpPort?: number captainDefinitionRelativeFilePath: string forceSsl: boolean + websocketSupport: boolean nodeId?: string instanceCount: number preDeployFunction?: string @@ -89,12 +90,12 @@ interface IAppDef extends IAppDefinitionBase { interface IAppDefSaved extends IAppDefinitionBase { appPushWebhook: - | { - tokenVersion: string - repoInfo: RepoInfoEncrypted - pushWebhookToken: string - } - | undefined + | { + tokenVersion: string + repoInfo: RepoInfoEncrypted + pushWebhookToken: string + } + | undefined httpAuth?: { user: string diff --git a/src/models/IServerBlockDetails.ts b/src/models/IServerBlockDetails.ts index 986530a..9892a6d 100644 --- a/src/models/IServerBlockDetails.ts +++ b/src/models/IServerBlockDetails.ts @@ -1,6 +1,7 @@ interface IServerBlockDetails { hasSsl: boolean forceSsl: boolean + websocketSupport: boolean publicDomain: string localDomain: string nginxConfigTemplate: string diff --git a/src/routes/user/apps/appdefinition/AppDefinitionRouter.ts b/src/routes/user/apps/appdefinition/AppDefinitionRouter.ts index 587411f..910cea3 100644 --- a/src/routes/user/apps/appdefinition/AppDefinitionRouter.ts +++ b/src/routes/user/apps/appdefinition/AppDefinitionRouter.ts @@ -339,6 +339,7 @@ router.post('/update/', function(req, res, next) { let notExposeAsWebApp = req.body.notExposeAsWebApp let customNginxConfig = req.body.customNginxConfig let forceSsl = !!req.body.forceSsl + let websocketSupport = !!req.body.websocketSupport let repoInfo = !!req.body.appPushWebhook ? req.body.appPushWebhook.repoInfo || {} : {} @@ -379,7 +380,8 @@ router.post('/update/', function(req, res, next) { ports, repoInfo, customNginxConfig, - preDeployFunction + preDeployFunction, + websocketSupport ) .then(function() { Logger.d('AppName is updated: ' + appName) diff --git a/src/user/ServiceManager.ts b/src/user/ServiceManager.ts index 9adf8c5..2c559dc 100644 --- a/src/user/ServiceManager.ts +++ b/src/user/ServiceManager.ts @@ -605,7 +605,8 @@ class ServiceManager { ports: IAppPort[], repoInfo: RepoInfo, customNginxConfig: string, - preDeployFunction: string + preDeployFunction: string, + websocketSupport: boolean ) { const self = this const dataStore = this.dataStore @@ -707,7 +708,8 @@ class ServiceManager { repoInfo, self.authenticator, customNginxConfig, - preDeployFunction + preDeployFunction, + websocketSupport ) }) .then(function() { diff --git a/src/user/system/LoadBalancerManager.ts b/src/user/system/LoadBalancerManager.ts index eb9f03a..eb3891a 100644 --- a/src/user/system/LoadBalancerManager.ts +++ b/src/user/system/LoadBalancerManager.ts @@ -253,6 +253,7 @@ class LoadBalancerManager { .getAppsDataStore() .getServiceName(appName) const forceSsl = !!webApp.forceSsl + const websocketSupport = !!webApp.websocketSupport const nginxConfigTemplate = webApp.customNginxConfig || defaultAppNginxConfig @@ -263,6 +264,7 @@ class LoadBalancerManager { appName + '.' + rootDomain serverWithSubDomain.localDomain = localDomain serverWithSubDomain.forceSsl = forceSsl + serverWithSubDomain.websocketSupport = websocketSupport const httpPort = webApp.containerHttpPort || 80 serverWithSubDomain.containerHttpPort = httpPort serverWithSubDomain.nginxConfigTemplate = nginxConfigTemplate @@ -283,6 +285,7 @@ class LoadBalancerManager { containerHttpPort: httpPort, hasSsl: d.hasSsl, forceSsl: forceSsl, + websocketSupport: websocketSupport, publicDomain: d.publicDomain, localDomain: localDomain, nginxConfigTemplate: nginxConfigTemplate, diff --git a/src/utils/MigrateCaptainDuckDuck.ts b/src/utils/MigrateCaptainDuckDuck.ts index 857651a..b5341b5 100644 --- a/src/utils/MigrateCaptainDuckDuck.ts +++ b/src/utils/MigrateCaptainDuckDuck.ts @@ -335,7 +335,8 @@ export default class MigrateCaptainDuckDuck { repoInfo, self.authenticator, app.customNginxConfig, - app.preDeployFunction + app.preDeployFunction, + false, ) }) }) diff --git a/template/server-block-conf.ejs b/template/server-block-conf.ejs index 9b27510..473ed4e 100644 --- a/template/server-block-conf.ejs +++ b/template/server-block-conf.ejs @@ -75,6 +75,15 @@ if (!s.forceSsl || s.hasSsl) { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + + <% + if (s.websocketSupport) { + %> + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + <% + } + %> } location /.well-known/ {