diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 41e5fad5ac..f8f71e0813 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -153,6 +153,8 @@ sql: # Actor system parameters actors: + cluster: + grpc_callback_thread_pool_size: "${ACTORS_CLUSTER_GRPC_CALLBACK_THREAD_POOL_SIZE:10}" tenant: create_components_on_init: "${ACTORS_TENANT_CREATE_COMPONENTS_ON_INIT:true}" session: diff --git a/docker/check-dirs.sh b/docker/check-dirs.sh deleted file mode 100755 index 2042a44aea..0000000000 --- a/docker/check-dirs.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2018 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -dirsArray=("./haproxy/certs.d" "./haproxy/letsencrypt" "./tb-node/postgres" "./tb-node/cassandra" "./tb-node/log/tb1" "./tb-node/log/tb2") - -for dir in ${dirsArray[@]} -do - if [ ! -d "$dir" ]; then - echo creating dir $dir - mkdir -p $dir - fi -done diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8f9666851b..267d56002d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -180,8 +180,6 @@ services: - ./haproxy/certs.d:/usr/local/etc/haproxy/certs.d ports: - "80:80" - - "8080" - - "8090" - "443:443" - "1883:1883" - "9999:9999" @@ -191,7 +189,6 @@ services: HTTP_PORT: 80 HTTPS_PORT: 443 MQTT_PORT: 1883 - TB_API_PORT: 8090 FORCE_HTTPS_REDIRECT: "false" links: - tb1 diff --git a/docker/docker-install-tb.sh b/docker/docker-install-tb.sh index 9032e2fd15..3816229f3a 100755 --- a/docker/docker-install-tb.sh +++ b/docker/docker-install-tb.sh @@ -15,8 +15,6 @@ # limitations under the License. # -./check-dirs.sh - while [[ $# -gt 0 ]] do key="$1" diff --git a/docker/docker-start-services.sh b/docker/docker-start-services.sh index 8437695a1a..452a823d42 100755 --- a/docker/docker-start-services.sh +++ b/docker/docker-start-services.sh @@ -15,8 +15,6 @@ # limitations under the License. # -./check-dirs.sh - set -e source compose-utils.sh diff --git a/docker/docker-upgrade-tb.sh b/docker/docker-upgrade-tb.sh index d83b1b7579..6f460f3baf 100755 --- a/docker/docker-upgrade-tb.sh +++ b/docker/docker-upgrade-tb.sh @@ -15,8 +15,6 @@ # limitations under the License. # -./check-dirs.sh - for i in "$@" do case $i in diff --git a/docker/haproxy/config/haproxy.cfg b/docker/haproxy/config/haproxy.cfg index 8ba0ce50c7..50566c93b9 100644 --- a/docker/haproxy/config/haproxy.cfg +++ b/docker/haproxy/config/haproxy.cfg @@ -56,13 +56,20 @@ frontend http-in reqadd X-Forwarded-Proto:\ http + acl acl_static path_beg /static/ /index.html + acl acl_static path / + acl acl_static_rulenode path_beg /static/rulenode/ + acl transport_http_acl path_beg /api/v1/ acl letsencrypt_http_acl path_beg /.well-known/acme-challenge/ + redirect scheme https if !letsencrypt_http_acl !transport_http_acl { env(FORCE_HTTPS_REDIRECT) -m str true } + use_backend letsencrypt_http if letsencrypt_http_acl use_backend tb-http-backend if transport_http_acl + use_backend tb-web-backend if acl_static !acl_static_rulenode - default_backend tb-web-backend + default_backend tb-api-backend frontend https_in bind *:${HTTPS_PORT} ssl crt /usr/local/etc/haproxy/default.pem crt /usr/local/etc/haproxy/certs.d ciphers ECDHE-RSA-AES256-SHA:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM @@ -72,14 +79,15 @@ frontend https_in reqadd X-Forwarded-Proto:\ https acl transport_http_acl path_beg /api/v1/ + + acl acl_static path_beg /static/ /index.html + acl acl_static path / + acl acl_static_rulenode path_beg /static/rulenode/ + use_backend tb-http-backend if transport_http_acl + use_backend tb-web-backend if acl_static !acl_static_rulenode - default_backend tb-web-backend - -frontend http-api-in - bind *:${TB_API_PORT} - - default_backend tb-api-backend + default_backend tb-api-backend backend letsencrypt_http server letsencrypt_http_srv 127.0.0.1:8080 diff --git a/docker/tb-web-ui.env b/docker/tb-web-ui.env index fc50db0744..3916337eeb 100644 --- a/docker/tb-web-ui.env +++ b/docker/tb-web-ui.env @@ -1,8 +1,7 @@ HTTP_BIND_ADDRESS=0.0.0.0 HTTP_BIND_PORT=8080 -TB_HOST=haproxy -TB_PORT=8090 +TB_ENABLE_PROXY=false LOGGER_LEVEL=info LOG_FOLDER=logs LOGGER_FILENAME=tb-web-ui-%DATE%.log diff --git a/msa/web-ui/build.gradle b/msa/web-ui/build.gradle index 7372c0a819..e298541b29 100644 --- a/msa/web-ui/build.gradle +++ b/msa/web-ui/build.gradle @@ -66,7 +66,7 @@ ospackage { } // Copy web files - from("target/package/linux/web") { + from("target/web") { into "web" } diff --git a/msa/web-ui/config/custom-environment-variables.yml b/msa/web-ui/config/custom-environment-variables.yml index 9472a50571..de357c9234 100644 --- a/msa/web-ui/config/custom-environment-variables.yml +++ b/msa/web-ui/config/custom-environment-variables.yml @@ -20,6 +20,7 @@ server: # Server bind port port: "HTTP_BIND_PORT" thingsboard: + enableProxy: "TB_ENABLE_PROXY" # ThingsBoard node host host: "TB_HOST" # ThingsBoard node port diff --git a/msa/web-ui/config/default.yml b/msa/web-ui/config/default.yml index cf27a14015..c7f3ba96f5 100644 --- a/msa/web-ui/config/default.yml +++ b/msa/web-ui/config/default.yml @@ -20,6 +20,7 @@ server: # Server bind port port: "8090" thingsboard: + enableProxy: "false" # ThingsBoard node host host: "localhost" # ThingsBoard node port diff --git a/msa/web-ui/server.js b/msa/web-ui/server.js index 44e175a84c..31d35a29fa 100644 --- a/msa/web-ui/server.js +++ b/msa/web-ui/server.js @@ -31,14 +31,19 @@ var server; const bindAddress = config.get('server.address'); const bindPort = config.get('server.port'); + const thingsboardEnableProxy = config.get('thingsboard.enableProxy'); + const thingsboardHost = config.get('thingsboard.host'); const thingsboardPort = config.get('thingsboard.port'); logger.info('Bind address: %s', bindAddress); logger.info('Bind port: %s', bindPort); + logger.info('ThingsBoard Enable Proxy: %s', thingsboardEnableProxy); logger.info('ThingsBoard host: %s', thingsboardHost); logger.info('ThingsBoard port: %s', thingsboardPort); + const useApiProxy = thingsboardEnableProxy === "true"; + var webDir = path.join(__dirname, 'web'); if (typeof process.env.WEB_FOLDER === 'string') { @@ -49,47 +54,51 @@ var server; const app = express(); server = http.createServer(app); - const apiProxy = httpProxy.createProxyServer({ - target: { - host: thingsboardHost, - port: thingsboardPort - } - }); + if (useApiProxy) { + const apiProxy = httpProxy.createProxyServer({ + target: { + host: thingsboardHost, + port: thingsboardPort + } + }); - apiProxy.on('error', function (err, req, res) { - logger.warn('API proxy error: %s', err.message); - res.writeHead(500); - if (err.code && err.code === 'ECONNREFUSED') { - res.end('Unable to connect to ThingsBoard server.'); - } else { - res.end('Thingsboard server connection error: ' + err.code ? err.code : ''); - } - }); + apiProxy.on('error', function (err, req, res) { + logger.warn('API proxy error: %s', err.message); + res.writeHead(500); + if (err.code && err.code === 'ECONNREFUSED') { + res.end('Unable to connect to ThingsBoard server.'); + } else { + res.end('Thingsboard server connection error: ' + err.code ? err.code : ''); + } + }); + } - const root = path.join(webDir, 'public'); + if (useApiProxy) { + app.all('/api/*', (req, res) => { + logger.debug(req.method + ' ' + req.originalUrl); + apiProxy.web(req, res); + }); - const staticDir = path.join(root, 'static'); - - app.all('/api/*', (req, res) => { - logger.debug(req.method + ' ' + req.originalUrl); - apiProxy.web(req, res); - }); - - app.all('/static/rulenode/*', (req, res) => { - apiProxy.web(req, res); - }); + app.all('/static/rulenode/*', (req, res) => { + apiProxy.web(req, res); + }); + } app.use(historyApiFallback()); - app.use('/static', express.static(staticDir)); + const root = path.join(webDir, 'public'); - app.get('*', (req, res) => { - apiProxy.web(req, res); - }); + app.use(express.static(root)); - server.on('upgrade', (req, socket, head) => { - apiProxy.ws(req, socket, head); - }); + if (useApiProxy) { + app.get('*', (req, res) => { + apiProxy.web(req, res); + }); + + server.on('upgrade', (req, socket, head) => { + apiProxy.ws(req, socket, head); + }); + } server.listen(bindPort, bindAddress, (error) => { if (error) {