Updated conection process to work hopfully with docker.
This commit is contained in:
@@ -1,32 +1,39 @@
|
|||||||
# Build everything in one stage
|
# Stage 1: Build frontend
|
||||||
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
|
FROM --platform=$BUILDPLATFORM node:18-alpine AS frontend-builder
|
||||||
|
|
||||||
# Install nginx and dependencies
|
|
||||||
RUN apk add --no-cache nginx npm
|
|
||||||
|
|
||||||
# Set working directory
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files and install dependencies
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
# Copy the entire project (frontend and backend)
|
|
||||||
COPY ./ ./
|
|
||||||
|
|
||||||
# Build the frontend
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 2: Build backend
|
||||||
|
FROM --platform=$BUILDPLATFORM node:18-alpine AS backend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY src/backend/ ./src/backend/
|
||||||
|
|
||||||
|
# Stage 3: Final production image
|
||||||
|
FROM node:18-alpine
|
||||||
|
RUN apk add --no-cache nginx
|
||||||
|
|
||||||
# Configure nginx
|
# Configure nginx
|
||||||
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY --from=frontend-builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy built frontend to nginx's web directory
|
# Copy backend
|
||||||
COPY ./dist /usr/share/nginx/html
|
COPY --from=backend-builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=backend-builder /app/src/backend ./src/backend
|
||||||
|
|
||||||
# Expose necessary ports
|
# Create separate directories for nginx and node
|
||||||
EXPOSE 8080
|
RUN mkdir -p /var/log/nginx && \
|
||||||
EXPOSE 8081
|
mkdir -p /var/lib/nginx && \
|
||||||
|
chown -R nginx:nginx /var/log/nginx /var/lib/nginx
|
||||||
|
|
||||||
# Use entrypoint.sh to run both the backend and nginx
|
# Expose ports
|
||||||
RUN chmod +x /app/src/backend/entrypoint.sh
|
EXPOSE 8080 8081
|
||||||
ENTRYPOINT ["/app/src/backend/entrypoint.sh"]
|
|
||||||
|
# Use a start script to run both services
|
||||||
|
COPY docker/entrypoint.sh /entrypoint.sh
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
CMD ["/entrypoint.sh"]
|
||||||
10
docker/entrypoint.sh
Normal file
10
docker/entrypoint.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Start NGINX in background
|
||||||
|
nginx -g "daemon off;" &
|
||||||
|
|
||||||
|
# Start Node.js backend
|
||||||
|
node src/backend/index.js
|
||||||
|
|
||||||
|
# Keep container running
|
||||||
|
wait
|
||||||
@@ -21,17 +21,16 @@ http {
|
|||||||
|
|
||||||
# Proxy IO requests
|
# Proxy IO requests
|
||||||
location /socket.io/ {
|
location /socket.io/ {
|
||||||
proxy_pass http://0.0.0.0: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';
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
|
||||||
# CORS settings
|
# Timeout settings
|
||||||
add_header 'Access-Control-Allow-Origin' '*';
|
proxy_read_timeout 86400s;
|
||||||
add_header 'Access-Control-Allow-Methods' '*';
|
proxy_send_timeout 86400s;
|
||||||
add_header 'Access-Control-Allow-Headers' '*';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Error pages
|
# Error pages
|
||||||
|
|||||||
@@ -70,14 +70,12 @@ export function NewTerminal({ hostConfig }) {
|
|||||||
// Write initial connection message
|
// Write initial connection message
|
||||||
terminal.write("\r\n*** Connecting to backend ***\r\n");
|
terminal.write("\r\n*** Connecting to backend ***\r\n");
|
||||||
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const socket = io(window.location.hostname === "localhost"
|
||||||
let ioUrl = `${protocol}//${window.location.hostname}:${window.location.port}/socket.io/`;
|
? 'http://localhost:8081'
|
||||||
|
: '/', {
|
||||||
if (window.location.hostname === "localhost") {
|
path: '/socket.io',
|
||||||
ioUrl = "http://localhost:8081";
|
transports: ['websocket', 'polling']
|
||||||
}
|
});
|
||||||
|
|
||||||
const socket = io(ioUrl);
|
|
||||||
socketRef.current = socket;
|
socketRef.current = socket;
|
||||||
|
|
||||||
socket.off("connect");
|
socket.off("connect");
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Start the backend server
|
|
||||||
node /app/src/backend/server.cjs &
|
|
||||||
|
|
||||||
# Start nginx in the foreground
|
|
||||||
exec nginx -g 'daemon off;'
|
|
||||||
@@ -5,9 +5,9 @@ const SSHClient = require("ssh2").Client;
|
|||||||
const server = http.createServer();
|
const server = http.createServer();
|
||||||
const io = socketIo(server, {
|
const io = socketIo(server, {
|
||||||
cors: {
|
cors: {
|
||||||
origin: "*", // Allow all origins
|
origin: "*",
|
||||||
methods: ["*"], // Allow all methods
|
methods: ["GET", "POST"],
|
||||||
allowedHeaders: ["*"], // Allow all headers
|
credentials: true
|
||||||
},
|
},
|
||||||
allowEIO3: true
|
allowEIO3: true
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user