File size: 1,121 Bytes
8210e63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
import app from "./app";
import { logger } from "./lib/logger";

const rawPort = process.env["PORT"];

if (!rawPort) {
  throw new Error(
    "PORT environment variable is required but was not provided.",
  );
}

const port = Number(rawPort);

if (Number.isNaN(port) || port <= 0) {
  throw new Error(`Invalid PORT value: "${rawPort}"`);
}

app.listen(port, (err) => {
  if (err) {
    logger.error({ err }, "Error listening on port");
    process.exit(1);
  }

  logger.info({ port }, "Server listening");

  // Phase 5: Start daily deadline checking & scheduling
  import("./lib/deadline-checker.js")
    .then(async ({ checkDeadlines, scheduleDailyCheck }) => {
      logger.info("Initializing Phase 5 Deadline Checker...");
      try {
        const sent = await checkDeadlines();
        logger.info({ sent }, "Startup deadline check completed.");
      } catch (checkErr) {
        logger.error({ err: checkErr }, "Startup deadline check failed");
      }
      scheduleDailyCheck();
    })
    .catch((importErr) => {
      logger.error({ err: importErr }, "Failed to import deadline-checker module");
    });
});