Changes to connection system to support docker
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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"],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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"],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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';
|
||||||
@@ -103,15 +106,15 @@ async function deleteUser(userId) {
|
|||||||
await User.deleteOne({ _id: userId });
|
await User.deleteOne({ _id: userId });
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} else {
|
} else {
|
||||||
return { error: 'User not found'};
|
return { error: 'User not found' };
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { error: 'Error removing user: ' + err.message };
|
return { error: 'Error removing user: ' + err.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -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"],
|
||||||
|
|||||||
Reference in New Issue
Block a user