config nginx to fix sse not found bug
This commit is contained in:
		
							parent
							
								
									075bcb40ed
								
							
						
					
					
						commit
						c9726d00a0
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -4,7 +4,7 @@ dist
 | 
			
		|||
dist-ssr
 | 
			
		||||
*.local
 | 
			
		||||
count.txt
 | 
			
		||||
.env
 | 
			
		||||
.env*
 | 
			
		||||
.nitro
 | 
			
		||||
.tanstack
 | 
			
		||||
.vscode/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,7 @@ server {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    location /api/ {
 | 
			
		||||
        proxy_pass http://backend_api;
 | 
			
		||||
        proxy_pass http://backend/;
 | 
			
		||||
 | 
			
		||||
        # CORS headers
 | 
			
		||||
        add_header 'Access-Control-Allow-Origin' '*' always;
 | 
			
		||||
| 
						 | 
				
			
			@ -36,4 +36,14 @@ server {
 | 
			
		|||
            return 204;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    location /api/Sse/events {
 | 
			
		||||
        proxy_pass http://backend/api/Sse/events;
 | 
			
		||||
        proxy_http_version 1.1;
 | 
			
		||||
 | 
			
		||||
        # cần thiết cho SSE
 | 
			
		||||
        proxy_set_header Connection '';
 | 
			
		||||
        proxy_buffering off;
 | 
			
		||||
        proxy_cache off;
 | 
			
		||||
        proxy_read_timeout 1h;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,38 +1,22 @@
 | 
			
		|||
const hostname = window.location.hostname;
 | 
			
		||||
console.log("Current hostname:", hostname);
 | 
			
		||||
var tailscaleIP = import.meta.env.VITE_IP_TAILSCALE;
 | 
			
		||||
var localIP = import.meta.env.VITE_IP_LOCAL;
 | 
			
		||||
const isDev = import.meta.env.MODE === "development";
 | 
			
		||||
 | 
			
		||||
let API_MODE: "tailscale" | "local" | "ip";
 | 
			
		||||
 | 
			
		||||
if (hostname.includes(tailscaleIP)) {
 | 
			
		||||
  API_MODE = "tailscale";
 | 
			
		||||
} else if (hostname === localIP) {
 | 
			
		||||
  API_MODE = "local";
 | 
			
		||||
} else {
 | 
			
		||||
  API_MODE = "ip";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const API_ROOT = {
 | 
			
		||||
  tailscale: import.meta.env.VITE_API_URL_TAILSCALE,
 | 
			
		||||
  local: import.meta.env.VITE_API_URL_LOCAL,
 | 
			
		||||
  ip: import.meta.env.VITE_API_URL_IP,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const BASE_URL = API_ROOT[API_MODE];
 | 
			
		||||
export const BASE_URL = isDev
 | 
			
		||||
  ? import.meta.env.VITE_API_URL_DEV
 | 
			
		||||
  : "/api";
 | 
			
		||||
 | 
			
		||||
export const API_ENDPOINTS = {
 | 
			
		||||
  APP_VERSION: {
 | 
			
		||||
    GET_VERSION: `/AppVersion/version`,
 | 
			
		||||
    UPLOAD: `/AppVersion/upload`,
 | 
			
		||||
    GET_VERSION: `${BASE_URL}/AppVersion/version`,
 | 
			
		||||
    UPLOAD: `${BASE_URL}/AppVersion/upload`,
 | 
			
		||||
  },
 | 
			
		||||
  DEVICE_COMM: {
 | 
			
		||||
    UPDATE_AGENT: `/DeviceComm/updateagent`,
 | 
			
		||||
    GET_ROOM_LIST: `/DeviceComm/rooms`,
 | 
			
		||||
    GET_DEVICE_FROM_ROOM: (roomName: string) => `/DeviceComm/room/${roomName}`,
 | 
			
		||||
    UPDATE_AGENT: `${BASE_URL}/DeviceComm/updateagent`,
 | 
			
		||||
    GET_ROOM_LIST: `${BASE_URL}/DeviceComm/rooms`,
 | 
			
		||||
    GET_DEVICE_FROM_ROOM: (roomName: string) =>
 | 
			
		||||
      `${BASE_URL}/DeviceComm/room/${roomName}`,
 | 
			
		||||
  },
 | 
			
		||||
  SSE_EVENTS: {
 | 
			
		||||
    DEVICE_ONLINE: `/Sse/events/onlineDevices`,
 | 
			
		||||
    DEVICE_OFFLINE: `/Sse/events/offlineDevices`,
 | 
			
		||||
    DEVICE_ONLINE: `${BASE_URL}/Sse/events/onlineDevices`,
 | 
			
		||||
    DEVICE_OFFLINE: `${BASE_URL}/Sse/events/offlineDevices`,
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,8 +16,8 @@ interface UseDeviceEventsOptions {
 | 
			
		|||
 | 
			
		||||
export function useDeviceEvents(options: UseDeviceEventsOptions) {
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const onlineES = new EventSource(`${BASE_URL}${API_ENDPOINTS.SSE_EVENTS.DEVICE_ONLINE}`);
 | 
			
		||||
    const offlineES = new EventSource(`${BASE_URL}${API_ENDPOINTS.SSE_EVENTS.DEVICE_OFFLINE}`);
 | 
			
		||||
    const onlineES = new EventSource(API_ENDPOINTS.SSE_EVENTS.DEVICE_ONLINE);
 | 
			
		||||
    const offlineES = new EventSource(API_ENDPOINTS.SSE_EVENTS.DEVICE_OFFLINE);
 | 
			
		||||
 | 
			
		||||
    onlineES.addEventListener("online", (event) => {
 | 
			
		||||
      try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,13 @@ function RoomComponent() {
 | 
			
		|||
      queryClient.setQueryData(["rooms"], (oldRooms: any[] = []) =>
 | 
			
		||||
        oldRooms.map((r) =>
 | 
			
		||||
          r.name === room
 | 
			
		||||
            ? { ...r, offlineCount: Math.max((r.offlineCount || 0) - 1, 0) }
 | 
			
		||||
            ? {
 | 
			
		||||
                ...r,
 | 
			
		||||
                numberOfOfflineDevices: Math.max(
 | 
			
		||||
                  (r.numberOfOfflineDevices || 0) - 1,
 | 
			
		||||
                  0
 | 
			
		||||
                ),
 | 
			
		||||
              }
 | 
			
		||||
            : r
 | 
			
		||||
        )
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +60,10 @@ function RoomComponent() {
 | 
			
		|||
      queryClient.setQueryData(["rooms"], (oldRooms: any[] = []) =>
 | 
			
		||||
        oldRooms.map((r) =>
 | 
			
		||||
          r.name === room
 | 
			
		||||
            ? { ...r, offlineCount: (r.offlineCount || 0) + 1 }
 | 
			
		||||
            ? {
 | 
			
		||||
                ...r,
 | 
			
		||||
                numberOfOfflineDevices: (r.numberOfOfflineDevices || 0) + 1,
 | 
			
		||||
              }
 | 
			
		||||
            : r
 | 
			
		||||
        )
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -76,8 +85,7 @@ function RoomComponent() {
 | 
			
		|||
    },
 | 
			
		||||
    {
 | 
			
		||||
      header: "Thiết bị offline",
 | 
			
		||||
      accessorKey: "offlineCount",
 | 
			
		||||
      cell: ({ getValue }) => getValue() || 0,
 | 
			
		||||
      accessorKey: "numberOfOfflineDevices",
 | 
			
		||||
    },
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user