-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (26 loc) · 991 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express=require('express');
const config=require('./config/config');
const { roundRobinHandler,performHealthCheck, weightedRoundRobinHandler, ipHash, weightedResponseTimeHandler, weightedLeastConnectionsHandler }=require('./utils/handler');
const app=express();
const PORT= process.env.PORT || 3000;
/*
Load Balancer implementation
*/
global.servers=config.servers
/*
Servers health check
*/
// Perform initial health check
performHealthCheck();
// Schedule periodic health checks (every 10 seconds in this example)
const healthCheckInterval = setInterval(performHealthCheck, 10 * 1000);
app.use('/weightedLeastConnections',weightedLeastConnectionsHandler)
app.use('/weightedResponseTime',weightedResponseTimeHandler)
app.use('/iphash',ipHash);
app.use("/weightedRoundRobin",weightedRoundRobinHandler);
app.use("*",roundRobinHandler());
app.listen(PORT,()=>{
console.log(`Load Balancer is running on port ${PORT}`);
});
// create servers
require('./utils/servers')