app.js(조회+ 실시간 Push )
index.html

위의 js를 두가지 케이스로 분리
1. 조회
2. 실시간 Push

server.js
0.00MB
api.js
0.00MB
index.html
0.02MB

 

Important Notes:

  • The two servers (server.js and api.js) communicate with the same Redis instance, so they should be run separately.
  • Both servers can be running simultaneously because they handle different aspects of the application: one for WebSocket communication and polling (real-time data push), and the other for HTTP-based API requests.

Potential Issues:

  • Redis Connection Timing: Ensure Redis is up and running before starting either server. If Redis is down or unreachable, both the WebSocket server and the Express API might fail to connect. To handle this, consider adding retries or proper error handling when trying to connect to Redis in both server.js and api.js.

1. Start Redis and WebSocket Server (server.js) First

  • Why: The WebSocket server is listening for connections, and it continuously polls Redis to fetch data. It needs to be up and running first so it can handle incoming WebSocket connections and start processing Redis data.
  • Action: Run node server.js first. This starts the WebSocket server and Redis polling.

2. Start the Express API Server (api.js) Second

  • Why: The Express API server handles HTTP requests, including setting the Redis public key, sending data to Redis, and fetching data from Redis. It needs to be running after the WebSocket server because it could be interacting with the Redis database that is already being accessed by the WebSocket server.
  • Action: After server.js is running, run node api.js. This starts the Express API server, which interacts with Redis.

font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;

<style>
#loading {
display: none; /* 기본적으로 숨김 */
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 40px; /* 2배로 증가 */
border-radius: 20px; /* 2배로 증가 */
    /*
font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
font-family: 'Apple SD Gothic Neo', '돋움', Dotum, sans-serif;
font-family: 'Poppins', sans-serif;
    */
font-family: 'Nunito Sans', sans-serif;
/*
font-family: 'Montserrat', sans-serif;
font-family: 'IBM Plex Sans', sans-serif;
font-family: 'Nunito Sans', sans-serif;
*/
font-size: 40px; /* 2배로 증가 */
}
    </style>

 

 

index.html
0.02MB

'Web(HTML)' 카테고리의 다른 글

Start Redis and WebSocket Server (server.js) First  (0) 2025.02.15

+ Recent posts