Add nginx to bypass websockets on node client app

This commit is contained in:
Reckless_Satoshi 2022-08-23 10:59:59 -07:00
parent 6ff8df6dad
commit 7b51f4dfe4
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 62 additions and 6 deletions

View File

@ -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

View File

@ -1 +1,2 @@
README.md
README.md
assets

View File

@ -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}
CMD ["bash", "robosats-client.sh"]

View File

@ -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

View File

42
nodeapp/nginx/local.conf Normal file
View File

@ -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;
}
}

View File

@ -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;"