arreglar localhost

This commit is contained in:
2026-01-17 22:24:56 -06:00
parent 64327ef5df
commit 153bdf2819
7 changed files with 43 additions and 13 deletions

View File

@@ -28,6 +28,9 @@ services:
restart: always
ports:
- "3002:80" # Web Interface
environment:
- VITE_API_URL=${VITE_API_URL:-http://localhost:3001}
- VITE_WS_URL=${VITE_WS_URL:-ws://localhost:3003}
depends_on:
- gateway
networks:

View File

@@ -9,5 +9,8 @@ RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

12
manager/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
# Generate config.js
cat <<EOF > /usr/share/nginx/html/config.js
window.APP_CONFIG = {
VITE_API_URL: "${VITE_API_URL}",
VITE_WS_URL: "${VITE_WS_URL}"
};
EOF
# Exec the passed command
exec "$@"

View File

@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8" />
@@ -6,6 +6,7 @@
<title>WhatsApp Gateway Manager</title>
</head>
<body>
<script src="/config.js"></script>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

4
manager/public/config.js Normal file
View File

@@ -0,0 +1,4 @@
window.APP_CONFIG = {
VITE_API_URL: "http://localhost:3001",
VITE_WS_URL: "ws://localhost:3003"
};

View File

@@ -9,7 +9,7 @@ export const Dashboard: React.FC = () => {
const [isConnected, setIsConnected] = useState(false);
useEffect(() => {
const wsUrl = import.meta.env.VITE_WS_URL || 'ws://localhost:3003';
const wsUrl = window.APP_CONFIG?.VITE_WS_URL || import.meta.env.VITE_WS_URL || 'ws://localhost:3003';
const service = new WebSocketService(wsUrl);
setWsService(service);
@@ -34,7 +34,7 @@ export const Dashboard: React.FC = () => {
const fetchGatewayStatus = async () => {
try {
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:3001';
const apiUrl = window.APP_CONFIG?.VITE_API_URL || import.meta.env.VITE_API_URL || 'http://localhost:3001';
const response = await fetch(`${apiUrl}/api/status`);
if (response.ok) {
const data = await response.json();

View File

@@ -1 +1,8 @@
/// <reference types="vite/client" />
interface Window {
APP_CONFIG?: {
VITE_API_URL: string;
VITE_WS_URL: string;
};
}