Skip to content

Commit

Permalink
Update LiveReloadServer.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Dec 22, 2024
1 parent dc935c8 commit 2eabf5a
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/ts/core/LiveReloadServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,23 @@ export class LiveReloadServer {
);

this.wss = new WebSocketServer({ server: this.server });
this.setupRateLimiter(); // Apply rate limiting
this.setupWebSocketHandlers();
this.setupMiddleware();
}

/**
* Sets up rate limiting middleware to prevent abuse.
*/
private setupRateLimiter(): void {
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per windowMs
message: "Too many requests from this IP, please try again later.",
});
this.app.use(limiter);
}

/**
* Sets up WebSocket handlers to manage client connections.
*/
Expand Down Expand Up @@ -103,15 +116,19 @@ export class LiveReloadServer {
);
this.app.use(express.static(publicPath));

// Apply rate limiting to the live reload script injection middleware
const rateLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `windowMs`
message: "Too many requests from this IP, please try again later.",
});

// Use rate limiter and inject middleware
this.app.use(rateLimiter, this.injectLiveReloadScript.bind(this));
// Middleware to inject the live reload script into HTML files
this.app.use(this.injectLiveReloadScript.bind(this));

// // Apply rate limiting to the live reload script injection middleware
// const rateLimiter = rateLimit({
// windowMs: 15 * 60 * 1000, // 15 minutes
// max: 100, // Limit each IP to 100 requests per `windowMs`
// message: "Too many requests from this IP, please try again later.",
// });

// // Use rate limiter and inject middleware
// this.app.use(rateLimiter, this.injectLiveReloadScript.bind(this));
}


Expand Down

0 comments on commit 2eabf5a

Please sign in to comment.