diff --git a/docker-compose.yml b/docker-compose.yml index 854f62e0..ed3fb71a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,6 +54,8 @@ services: TOR_PROXY_PORT: 9050 ROBOSATS_ONION: robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion network_mode: service:tor + volumes: + - ./frontend/static:/usr/src/robosats/static clean-orders: image: backend diff --git a/nodeapp/.dockerignore b/nodeapp/.dockerignore index 42061c01..17ed95fa 100644 --- a/nodeapp/.dockerignore +++ b/nodeapp/.dockerignore @@ -1 +1,2 @@ -README.md \ No newline at end of file +README.md +assets \ No newline at end of file diff --git a/nodeapp/Dockerfile b/nodeapp/Dockerfile index 9f1ec021..ab73e298 100644 --- a/nodeapp/Dockerfile +++ b/nodeapp/Dockerfile @@ -4,13 +4,13 @@ RUN mkdir -p /usr/src/robosats WORKDIR /usr/src/robosats COPY . . +COPY ./nginx/local.conf /etc/nginx/conf.d/local.conf +RUN touch ./selfhosted RUN apt-get update -RUN apt-get install -y socat +RUN apt-get install -y socat nginx RUN npm install http-server -RUN echo 'true' > static/selfhosted - EXPOSE 12596 -CMD npm exec http-server -- . -p 12596 -P http://127.0.0.1:81 -i false -d false & nohup socat tcp4-LISTEN:81,reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${ROBOSATS_ONION:-robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion}:80,socksport=${TOR_PROXY_PORT:-9050} \ No newline at end of file +CMD ["bash", "robosats-client.sh"] \ No newline at end of file diff --git a/nodeapp/README.md b/nodeapp/README.md index d180e9c9..bd84c2d3 100644 --- a/nodeapp/README.md +++ b/nodeapp/README.md @@ -6,7 +6,7 @@ At the moment it has no special integration with your local lightning wallet (e. # How it works -The container launches two processes: 1) A `socat` that will expose RoboSats coordinator API over HTTP on localhost:81 using the docker orchestration TOR socks proxy and 2) a `http-server` that serves all static files (including the Javascript client app) directly from your own node (should reduce loading times by a lot). Every request that cannot be served by your node http-server will be forwarded to the RoboSats coordinator (that is: API calls and Robot avatar images). +The container launches two processes: 1) A `socat` that will expose RoboSats coordinator API over HTTP on localhost:81 using the docker orchestration TOR socks proxy and 2) a `http-server` that serves all static files (including the Javascript client app) directly from your own node (should reduce loading times by a lot). Every request that cannot be served by your node http-server will be forwarded to the RoboSats coordinator (that is: API calls and Robot avatar images). Nginx is used to bypass `http-server` for websockets directly into the `socat` bridge as `http-server` does not support websockets connections. # Why host your own RoboSats client diff --git a/nodeapp/selfhosted b/nodeapp/assets/icon/.gitkeep similarity index 100% rename from nodeapp/selfhosted rename to nodeapp/assets/icon/.gitkeep diff --git a/nodeapp/assets/images/.gitkeep b/nodeapp/assets/images/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/nodeapp/nginx/local.conf b/nodeapp/nginx/local.conf new file mode 100644 index 00000000..3a2755ae --- /dev/null +++ b/nodeapp/nginx/local.conf @@ -0,0 +1,42 @@ +# first we declare our upstream server, which is our http-server application +upstream robosats_http_server { + server localhost:9000; + +} + +upstream robosats_websocket { + server localhost:81; +} + +# now we declare our main server +server { + + listen 12596; + server_name robosats_client; + + # location /static { + # alias /usr/src/static; + # } + + location / { + # requests are passed to npm Http-Server + proxy_pass http://robosats_http_server; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + + location /ws/ { + # websockets are passed to socat bridge + proxy_pass http://robosats_websocket; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location = /favicon.ico { + alias /usr/src/robosats/static/assets/images/favicon-96x96.png; + } +} diff --git a/nodeapp/robosats-client.sh b/nodeapp/robosats-client.sh new file mode 100644 index 00000000..0b9e76f5 --- /dev/null +++ b/nodeapp/robosats-client.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Runs three simple services on a single container (why? simpler deployment) +# 1) http-server: serves client app and static files within the image. Sends API requests to socat bridge. +# 2) socat: exposes remote RoboSats backend from TOR socks to http//localhost:81. +# 3) nginx: is just a hack to bypass http-server directly to socat for websocket connections (http-server does not support WS) + +client_server="npm exec http-server -- . -p 9000 -P http://127.0.0.1:81 -i false -d false" +backend_tor_bridge="socat tcp4-LISTEN:81,reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${ROBOSATS_ONION:-robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion}:80,socksport=${TOR_PROXY_PORT:-9050}" + +$client_server & $backend_tor_bridge & nginx -g "daemon off;" \ No newline at end of file