Changes to connection system to support docker

This commit is contained in:
Karmaa
2025-03-12 18:59:03 -05:00
parent bd79e1e5c3
commit 615c8d4ceb
5 changed files with 25 additions and 12 deletions

View File

@@ -24,19 +24,28 @@ http {
proxy_pass http://127.0.0.1:8081; proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade'; proxy_set_header Connection "Upgrade"; # Fix this line to properly upgrade WebSockets
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# Pass real IPs for logging and security
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} }
# Proxy database requests
location /database.io/ { location /database.io/ {
proxy_pass http://127.0.0.1:8082; proxy_pass http://127.0.0.1:8082;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade'; proxy_set_header Connection "Upgrade";
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade; proxy_cache_bypass $http_upgrade;
# Allow WebSockets to function properly
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} }
# Error pages # Error pages

View File

@@ -63,10 +63,10 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
const socket = io( const socket = io(
window.location.hostname === "localhost" window.location.hostname === "localhost"
? "http://localhost:8081" ? "http://localhost:8081/ssh.io"
: "/", : "/ssh.io",
{ {
path: "/ssh.io/", path: "/ssh.io/socket.io",
transports: ["websocket", "polling"], transports: ["websocket", "polling"],
} }
); );

View File

@@ -7,10 +7,10 @@ let socket;
if (!socket) { if (!socket) {
socket = io( socket = io(
window.location.hostname === "localhost" window.location.hostname === "localhost"
? "http://localhost:8082" ? "http://localhost:8082/database.io"
: "/", : "/database.io",
{ {
path: "/database.io", path: "/database.io/socket.io",
transports: ["websocket", "polling"], transports: ["websocket", "polling"],
} }
); );

View File

@@ -6,6 +6,7 @@ require('dotenv').config();
const server = http.createServer(); const server = http.createServer();
const io = socketIo(server, { const io = socketIo(server, {
path: "/database.io/socket.io",
cors: { cors: {
origin: "*", origin: "*",
methods: ["GET", "POST"], methods: ["GET", "POST"],
@@ -14,6 +15,8 @@ const io = socketIo(server, {
allowEIO3: true allowEIO3: true
}); });
const dbNamespace = io.of("/database.io");
async function connectToMongoDB() { async function connectToMongoDB() {
try { try {
const mongoUrl = process.env.MONGO_URL || 'mongodb://mongodb:27017/termix'; const mongoUrl = process.env.MONGO_URL || 'mongodb://mongodb:27017/termix';
@@ -110,8 +113,8 @@ async function deleteUser(userId) {
} }
} }
io.on("connection", (socket) => { dbNamespace.on("connection", (socket) => {
console.log("New socket connection established"); console.log("New socket connection established on");
socket.on("createUser", async (data) => { socket.on("createUser", async (data) => {
const { username, password } = data; const { username, password } = data;

View File

@@ -4,6 +4,7 @@ const SSHClient = require("ssh2").Client;
const server = http.createServer(); const server = http.createServer();
const io = socketIo(server, { const io = socketIo(server, {
path: "/ssh.io/socket.io",
cors: { cors: {
origin: "*", origin: "*",
methods: ["GET", "POST"], methods: ["GET", "POST"],