Allow CORS
Этот коммит содержится в:
@@ -166,6 +166,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
// All api response bodies will be JSON formatted by default
|
// All api response bodies will be JSON formatted by default
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if len(utils.Cfg.ServiceSettings.AllowCorsFrom) > 0 {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", utils.Cfg.ServiceSettings.AllowCorsFrom)
|
||||||
|
}
|
||||||
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
w.Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
"EnableDeveloper": false,
|
"EnableDeveloper": false,
|
||||||
"EnableSecurityFixAlert": true,
|
"EnableSecurityFixAlert": true,
|
||||||
"EnableInsecureOutgoingConnections": false,
|
"EnableInsecureOutgoingConnections": false,
|
||||||
|
"AllowCorsFrom": "",
|
||||||
"SessionLengthWebInDays": 30,
|
"SessionLengthWebInDays": 30,
|
||||||
"SessionLengthMobileInDays": 30,
|
"SessionLengthMobileInDays": 30,
|
||||||
"SessionLengthSSOInDays": 30,
|
"SessionLengthSSOInDays": 30,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ type ServiceSettings struct {
|
|||||||
EnableDeveloper *bool
|
EnableDeveloper *bool
|
||||||
EnableSecurityFixAlert *bool
|
EnableSecurityFixAlert *bool
|
||||||
EnableInsecureOutgoingConnections *bool
|
EnableInsecureOutgoingConnections *bool
|
||||||
|
AllowCorsFrom string
|
||||||
SessionLengthWebInDays *int
|
SessionLengthWebInDays *int
|
||||||
SessionLengthMobileInDays *int
|
SessionLengthMobileInDays *int
|
||||||
SessionLengthSSOInDays *int
|
SessionLengthSSOInDays *int
|
||||||
|
|||||||
@@ -236,5 +236,7 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
||||||
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
|
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
|
||||||
|
|
||||||
|
props["AllowCorsFrom"] = c.ServiceSettings.AllowCorsFrom
|
||||||
|
|
||||||
return props
|
return props
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ var holders = defineMessages({
|
|||||||
id: 'admin.service.sessionDaysEx',
|
id: 'admin.service.sessionDaysEx',
|
||||||
defaultMessage: 'Ex "30"'
|
defaultMessage: 'Ex "30"'
|
||||||
},
|
},
|
||||||
|
corsExample: {
|
||||||
|
id: 'admin.service.corsEx',
|
||||||
|
defaultMessage: 'http://example.com'
|
||||||
|
},
|
||||||
saving: {
|
saving: {
|
||||||
id: 'admin.service.saving',
|
id: 'admin.service.saving',
|
||||||
defaultMessage: 'Saving Config...'
|
defaultMessage: 'Saving Config...'
|
||||||
@@ -131,6 +135,8 @@ class ServiceSettings extends React.Component {
|
|||||||
config.ServiceSettings.SessionCacheInMinutes = SessionCacheInMinutes;
|
config.ServiceSettings.SessionCacheInMinutes = SessionCacheInMinutes;
|
||||||
ReactDOM.findDOMNode(this.refs.SessionCacheInMinutes).value = SessionCacheInMinutes;
|
ReactDOM.findDOMNode(this.refs.SessionCacheInMinutes).value = SessionCacheInMinutes;
|
||||||
|
|
||||||
|
config.ServiceSettings.AllowCorsFrom = ReactDOM.findDOMNode(this.refs.AllowCorsFrom).value.trim();
|
||||||
|
|
||||||
Client.saveConfig(
|
Client.saveConfig(
|
||||||
config,
|
config,
|
||||||
() => {
|
() => {
|
||||||
@@ -763,6 +769,35 @@ class ServiceSettings extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className='form-group'>
|
||||||
|
<label
|
||||||
|
className='control-label col-sm-4'
|
||||||
|
htmlFor='AllowCorsFrom'
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.service.corsTitle'
|
||||||
|
defaultMessage='Allow Cross-origin Requests from:'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div className='col-sm-8'>
|
||||||
|
<input
|
||||||
|
type='text'
|
||||||
|
className='form-control'
|
||||||
|
id='AllowCorsFrom'
|
||||||
|
ref='AllowCorsFrom'
|
||||||
|
placeholder={formatMessage(holders.corsExample)}
|
||||||
|
defaultValue={this.props.config.ServiceSettings.AllowCorsFrom}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
<p className='help-text'>
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.service.corsDescription'
|
||||||
|
defaultMessage='Enable HTTP Cross origin request from a specific domain. Use "*" if you want to allow CORS from any domain or leave it blank to disable it.'
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label
|
<label
|
||||||
className='control-label col-sm-4'
|
className='control-label col-sm-4'
|
||||||
|
|||||||
@@ -294,6 +294,9 @@
|
|||||||
"admin.service.attemptTitle": "Maximum Login Attempts:",
|
"admin.service.attemptTitle": "Maximum Login Attempts:",
|
||||||
"admin.service.cmdsDesc": "When true, user created slash commands will be allowed.",
|
"admin.service.cmdsDesc": "When true, user created slash commands will be allowed.",
|
||||||
"admin.service.cmdsTitle": "Enable Slash Commands: ",
|
"admin.service.cmdsTitle": "Enable Slash Commands: ",
|
||||||
|
"admin.service.corsEx": "http://example.com https://example.com",
|
||||||
|
"admin.service.corsDescription": "Enable HTTP Cross origin request from specific domains (separate by a spacebar). Use \"*\" if you want to allow CORS from any domain or leave it blank to disable it.",
|
||||||
|
"admin.service.corsTitle": "Allow Cross-origin Requests from:",
|
||||||
"admin.service.developerDesc": "(Developer Option) When true, extra information around errors will be displayed in the UI.",
|
"admin.service.developerDesc": "(Developer Option) When true, extra information around errors will be displayed in the UI.",
|
||||||
"admin.service.developerTitle": "Enable Developer Mode: ",
|
"admin.service.developerTitle": "Enable Developer Mode: ",
|
||||||
"admin.service.false": "false",
|
"admin.service.false": "false",
|
||||||
|
|||||||
@@ -294,6 +294,9 @@
|
|||||||
"admin.service.attemptTitle": "Máximo de intentos de conexión:",
|
"admin.service.attemptTitle": "Máximo de intentos de conexión:",
|
||||||
"admin.service.cmdsDesc": "Cuando es verdadero, se permite la creación de comandos de barra por usuarios.",
|
"admin.service.cmdsDesc": "Cuando es verdadero, se permite la creación de comandos de barra por usuarios.",
|
||||||
"admin.service.cmdsTitle": "Habilitar Comandos de Barra: ",
|
"admin.service.cmdsTitle": "Habilitar Comandos de Barra: ",
|
||||||
|
"admin.service.corsEx": "http://ejemplo.com https://ejemplo.com",
|
||||||
|
"admin.service.corsDescription": "Habilita las solicitudes HTTP de origen cruzado para dominios en específico (separados por un espacio). Utiliza \"*\" si quieres habilitar CORS desde cualquier dominio o deja el campo en blanco para deshabilitarlo.",
|
||||||
|
"admin.service.corsTitle": "Permitir Solicitudes de Origen Cruzado desde:",
|
||||||
"admin.service.developerDesc": "(Opción de Desarrollador) Cuando está asignado en verdadero, información extra sobre errores se muestra en el UI.",
|
"admin.service.developerDesc": "(Opción de Desarrollador) Cuando está asignado en verdadero, información extra sobre errores se muestra en el UI.",
|
||||||
"admin.service.developerTitle": "Habilitar modo de Desarrollador: ",
|
"admin.service.developerTitle": "Habilitar modo de Desarrollador: ",
|
||||||
"admin.service.false": "falso",
|
"admin.service.false": "falso",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user