-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
30 lines (24 loc) · 964 Bytes
/
api.ts
File metadata and controls
30 lines (24 loc) · 964 Bytes
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
/** Mock API server: simulates HTTP request handling for demo purposes */
const PORT = Deno.env.get("PORT") || "3000";
console.log(`API server starting on port ${PORT}...`);
console.log(`Connected to database`);
console.log(`API ready at http://localhost:${PORT}`);
let requestCount = 0;
const interval = setInterval(() => {
requestCount++;
const endpoints = ["GET /users", "POST /orders", "GET /products", "PUT /cart", "DELETE /session"];
const endpoint = endpoints[Math.floor(Math.random() * endpoints.length)];
const ms = Math.floor(Math.random() * 50) + 5;
console.log(`${endpoint} - ${ms}ms`);
}, 2000);
Deno.addSignalListener("SIGTERM", () => {
console.log(`\nReceived SIGTERM, shutting down...`);
console.log(`Processed ${requestCount} requests`);
clearInterval(interval);
Deno.exit(0);
});
Deno.addSignalListener("SIGINT", () => {
console.log(`\nReceived SIGINT, shutting down...`);
clearInterval(interval);
Deno.exit(0);
});