thingsboard-aplcache
Changes
docker/docker-compose.yml 3(+0 -3)
docker/docker-install-tb.sh 2(+0 -2)
docker/docker-start-services.sh 2(+0 -2)
docker/docker-upgrade-tb.sh 2(+0 -2)
docker/haproxy/config/haproxy.cfg 20(+14 -6)
docker/tb-web-ui.env 3(+1 -2)
msa/web-ui/build.gradle 2(+1 -1)
msa/web-ui/config/default.yml 1(+1 -0)
msa/web-ui/server.js 77(+43 -34)
Details
diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml
index 41e5fad..f8f71e0 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:
docker/docker-compose.yml 3(+0 -3)
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 8f96668..267d560 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
docker/docker-install-tb.sh 2(+0 -2)
diff --git a/docker/docker-install-tb.sh b/docker/docker-install-tb.sh
index 9032e2f..3816229 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"
docker/docker-start-services.sh 2(+0 -2)
diff --git a/docker/docker-start-services.sh b/docker/docker-start-services.sh
index 8437695..452a823 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
docker/docker-upgrade-tb.sh 2(+0 -2)
diff --git a/docker/docker-upgrade-tb.sh b/docker/docker-upgrade-tb.sh
index d83b1b7..6f460f3 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
docker/haproxy/config/haproxy.cfg 20(+14 -6)
diff --git a/docker/haproxy/config/haproxy.cfg b/docker/haproxy/config/haproxy.cfg
index 8ba0ce5..50566c9 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/
- use_backend tb-http-backend if transport_http_acl
- default_backend tb-web-backend
+ acl acl_static path_beg /static/ /index.html
+ acl acl_static path /
+ acl acl_static_rulenode path_beg /static/rulenode/
-frontend http-api-in
- bind *:${TB_API_PORT}
+ use_backend tb-http-backend if transport_http_acl
+ use_backend tb-web-backend if acl_static !acl_static_rulenode
- default_backend tb-api-backend
+ default_backend tb-api-backend
backend letsencrypt_http
server letsencrypt_http_srv 127.0.0.1:8080
docker/tb-web-ui.env 3(+1 -2)
diff --git a/docker/tb-web-ui.env b/docker/tb-web-ui.env
index fc50db0..3916337 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
msa/web-ui/build.gradle 2(+1 -1)
diff --git a/msa/web-ui/build.gradle b/msa/web-ui/build.gradle
index 7372c0a..e298541 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 9472a50..de357c9 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
msa/web-ui/config/default.yml 1(+1 -0)
diff --git a/msa/web-ui/config/default.yml b/msa/web-ui/config/default.yml
index cf27a14..c7f3ba9 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
msa/web-ui/server.js 77(+43 -34)
diff --git a/msa/web-ui/server.js b/msa/web-ui/server.js
index 44e175a..31d35a2 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
- }
- });
-
- 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');
-
- const staticDir = path.join(root, 'static');
+ 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 : '');
+ }
+ });
+ }
- app.all('/api/*', (req, res) => {
- logger.debug(req.method + ' ' + req.originalUrl);
- apiProxy.web(req, res);
- });
+ if (useApiProxy) {
+ 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) {