Skip to content

Commit 1e2d453

Browse files
José Ángel Galindo DuarteJosé Ángel Galindo Duarte
authored andcommitted
fix: updating server config
1 parent 6d6f94f commit 1e2d453

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

docker-entrypoint-collab.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
# Entrypoint for the collab (:develop) image. Runs two processes in one
3+
# container: the Y.js collab server (loopback only, fronted by nginx) and nginx
4+
# serving the SPA. If either exits, the container exits so the orchestrator
5+
# (Watchtower) can restart it cleanly. Written for busybox ash (no `wait -n`).
6+
set -e
7+
8+
# Collab server, bound to loopback — only reachable through the nginx /collab
9+
# reverse proxy, never published directly.
10+
COLLAB_HOST=127.0.0.1 COLLAB_PORT=1234 node /collab/server/collab-server.js &
11+
collab_pid=$!
12+
13+
# nginx in the foreground process group.
14+
nginx -g 'daemon off;' &
15+
nginx_pid=$!
16+
17+
# Forward termination signals to both children.
18+
trap 'kill "$collab_pid" "$nginx_pid" 2>/dev/null' TERM INT
19+
20+
# Poll: as soon as either process is gone, stop the container (non-zero exit so
21+
# the orchestrator restarts it).
22+
while kill -0 "$collab_pid" 2>/dev/null && kill -0 "$nginx_pid" 2>/dev/null; do
23+
sleep 5
24+
done
25+
26+
kill "$collab_pid" "$nginx_pid" 2>/dev/null || true
27+
exit 1

nginx.collab.conf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# /etc/nginx/nginx.conf (collab / develop image)
2+
#
3+
# Superset of nginx.conf: in addition to serving the static SPA it reverse-
4+
# proxies the bundled Y.js collab backend (node, listening on 127.0.0.1:1234)
5+
# so collaboration rides the same origin/port as the app. The frontend is built
6+
# with VITE_COLLAB_URL=<scheme>://<host>/collab, so:
7+
# - WebSocket sessions hit /collab/<docId> -> node /<docId>
8+
# - the pre-flight health check hits /health -> node /health
9+
# The collab server is never exposed directly; only port 80 is published.
10+
11+
# njs dynamic module — bundled with the official nginx:alpine image.
12+
# Required for the /raw endpoint that serves decoded UVL content to UVLHub.
13+
load_module modules/ngx_http_js_module.so;
14+
15+
events {
16+
worker_connections 1024;
17+
}
18+
19+
http {
20+
include /etc/nginx/mime.types;
21+
default_type application/octet-stream;
22+
23+
sendfile on;
24+
keepalive_timeout 65;
25+
26+
js_path "/etc/nginx/njs/";
27+
js_import raw from raw.js;
28+
29+
# Bundled collab (Y.js websocket) server.
30+
upstream collab_backend {
31+
server 127.0.0.1:1234;
32+
}
33+
34+
server {
35+
listen 80;
36+
server_name localhost;
37+
38+
root /usr/share/nginx/html;
39+
index index.html;
40+
41+
# Decodes a base64 UVL model from ?model= and returns it as plain text
42+
# so that UVLHub can fetch the raw UVL content server-side.
43+
location /raw {
44+
js_content raw.handler;
45+
}
46+
47+
# Collab WebSocket sessions. Trailing slash strips the /collab/ prefix
48+
# so the doc id reaches the Y.js server as its room name (/<docId>).
49+
location /collab/ {
50+
proxy_pass http://collab_backend/;
51+
proxy_http_version 1.1;
52+
proxy_set_header Upgrade $http_upgrade;
53+
proxy_set_header Connection "upgrade";
54+
proxy_set_header Host $host;
55+
proxy_set_header X-Real-IP $remote_addr;
56+
proxy_read_timeout 3600s;
57+
proxy_send_timeout 3600s;
58+
}
59+
60+
# Health probe the frontend pings before opening a session.
61+
location = /health {
62+
proxy_pass http://collab_backend/health;
63+
proxy_set_header Host $host;
64+
}
65+
66+
location / {
67+
try_files $uri /index.html;
68+
}
69+
70+
gzip on;
71+
gzip_types text/css application/javascript application/json image/svg+xml;
72+
gzip_min_length 1000;
73+
}
74+
}

server/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "flamapy-ide-collab-server",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "Standalone runtime deps for the Y.js collaboration server bundled into the develop Docker image. Versions mirror the root package.json.",
6+
"type": "module",
7+
"main": "collab-server.js",
8+
"scripts": {
9+
"start": "node collab-server.js"
10+
},
11+
"dependencies": {
12+
"ws": "^8.18.0",
13+
"y-websocket": "^1.5.4",
14+
"yjs": "^13.6.18"
15+
}
16+
}

0 commit comments

Comments
 (0)