mirror of
https://github.com/caprover/caprover
synced 2026-09-26 16:45:39 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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,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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -335,7 +335,8 @@ export default class MigrateCaptainDuckDuck {
|
||||
repoInfo,
|
||||
self.authenticator,
|
||||
app.customNginxConfig,
|
||||
app.preDeployFunction
|
||||
app.preDeployFunction,
|
||||
false,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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/ {
|
||||
|
||||
Reference in New Issue
Block a user