-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (51 loc) · 1.73 KB
/
app.js
File metadata and controls
59 lines (51 loc) · 1.73 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express from "express";
import cors from "cors";
import { DATABASE_URL } from "./src/config/env.js";
import investmentRouter from "./src/routes/investmentRoute.js";
import { router as corpRouter } from "./src/routes/corpRoute.js";
import { router as compareTotalRouter } from "./src/routes/compareTotalRoute.js";
import { router as compareRouter } from "./src/routes/compareRoute.js";
import swaggerUi from "swagger-ui-express";
import swaggerSpec from "./src/swagger/swagger.js";
import cron from "node-cron";
import morgan from "morgan";
//투자금 등등은 너무 커서 BigInt 로 세팅한거 조회하기 위한 작업
BigInt.prototype.toJSON = function () {
return this.toString();
};
const app = express();
//cors 오류 방지 - 모든 도메인 허용
app.use(cors());
app.use(express.json());
app.use(morgan("combined"));
//Swagger UI
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerSpec, { explorer: true })
);
// cron - /health 엔드포인트 추가
app.get("/health", (req, res) => {
res.status(200).json({ status: "alive" });
});
app.use("/corp", corpRouter);
app.use("/corpTotals", compareTotalRouter);
app.use("/compare", compareRouter);
app.use("/", investmentRouter);
//cron 스케쥴러 - 10분에 한 번씩
cron.schedule("*/10 * * * *", async () => {
try {
const response = await fetch(
"https://eight-viewmystartup-4-be.onrender.com/health"
);
console.log(
`[${new Date().toISOString()}] Ping sent, status: ${response.status}`
);
} catch (error) {
console.error(`[${new Date().toISOString()}] Ping failed:`, error.message);
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}/api-docs`);
});