o134 commited on
Commit
8210e63
·
verified ·
1 Parent(s): 1758540

Upload api-server\src\index.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. api-server//src//index.ts +41 -0
api-server//src//index.ts ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import app from "./app";
2
+ import { logger } from "./lib/logger";
3
+
4
+ const rawPort = process.env["PORT"];
5
+
6
+ if (!rawPort) {
7
+ throw new Error(
8
+ "PORT environment variable is required but was not provided.",
9
+ );
10
+ }
11
+
12
+ const port = Number(rawPort);
13
+
14
+ if (Number.isNaN(port) || port <= 0) {
15
+ throw new Error(`Invalid PORT value: "${rawPort}"`);
16
+ }
17
+
18
+ app.listen(port, (err) => {
19
+ if (err) {
20
+ logger.error({ err }, "Error listening on port");
21
+ process.exit(1);
22
+ }
23
+
24
+ logger.info({ port }, "Server listening");
25
+
26
+ // Phase 5: Start daily deadline checking & scheduling
27
+ import("./lib/deadline-checker.js")
28
+ .then(async ({ checkDeadlines, scheduleDailyCheck }) => {
29
+ logger.info("Initializing Phase 5 Deadline Checker...");
30
+ try {
31
+ const sent = await checkDeadlines();
32
+ logger.info({ sent }, "Startup deadline check completed.");
33
+ } catch (checkErr) {
34
+ logger.error({ err: checkErr }, "Startup deadline check failed");
35
+ }
36
+ scheduleDailyCheck();
37
+ })
38
+ .catch((importErr) => {
39
+ logger.error({ err: importErr }, "Failed to import deadline-checker module");
40
+ });
41
+ });