add websocket support

- add a new config "websocketSupport" to the app definition
- use this config to add "upgrade headers" to nginx config
This commit is contained in:
sean-nicholas
2019-08-11 15:45:02 +02:00
parent 81d274755b
commit 3dbc3f8f89
8 changed files with 33 additions and 11 deletions
+4 -1
View File
@@ -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)
+7 -6
View File
@@ -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
+1
View File
@@ -1,6 +1,7 @@
interface IServerBlockDetails {
hasSsl: boolean
forceSsl: boolean
websocketSupport: boolean
publicDomain: string
localDomain: string
nginxConfigTemplate: string
@@ -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)
+4 -2
View File
@@ -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() {
+3
View File
@@ -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,
+2 -1
View File
@@ -335,7 +335,8 @@ export default class MigrateCaptainDuckDuck {
repoInfo,
self.authenticator,
app.customNginxConfig,
app.preDeployFunction
app.preDeployFunction,
false,
)
})
})
+9
View File
@@ -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/ {