Skip to content

Commit aeb53fa

Browse files
committed
fix some misc issues
1 parent 8af13ff commit aeb53fa

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

fly.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ processes = ['app']
1818
memory = '1gb'
1919
cpu_kind = 'shared'
2020
cpus = 1
21+
22+
[env]
23+
HOST = "0.0.0.0"
24+
PORT = "3000"

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ app.use("/", router);
122122
// );
123123
//
124124

125-
server.listen(port, "0.0.0.0", () => {
126-
logger.info(`Server is running on port ${port}`);
127-
});
125+
server
126+
.listen(Number(port), "0.0.0.0", () => {
127+
logger.info(`Server is running on port ${port}`);
128+
})
129+
.on("error", (err) => {
130+
logger.error(`Failed to start server: ${err.message}`);
131+
});

src/router.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,44 @@ router.get("/", logRequest, (req, res) => {
4242

4343
/**
4444
* GET /up
45-
* @summary Check if the API is up
46-
* @return {object} 200 - Success message
47-
* @example response - 200 - Success message
45+
* @summary Check if the API and database are up
46+
* @return {object} 200 - Status response
47+
* @example response - 200 - Success with database connection
4848
* {
49-
* "status": "up"
49+
* "status": "up",
50+
* "database": {
51+
* "connected": true,
52+
* "ping": "42ms",
53+
* "lastError": null
54+
* }
55+
* }
56+
* @example response - 200 - Success with database error
57+
* {
58+
* "status": "up",
59+
* "database": {
60+
* "connected": false,
61+
* "ping": null,
62+
* "lastError": {
63+
* "message": "Connection refused",
64+
* "timestamp": "2025-01-09T12:00:00Z"
65+
* }
66+
* }
5067
* }
5168
*/
5269
router.get("/up", logRequest, async (req, res) => {
5370
try {
5471
// Record start time for ping calculation
5572
const startTime = Date.now();
56-
5773
// Check database connectivity with a simple query
5874
await prisma.$queryRaw`SELECT 1`;
59-
6075
// Calculate ping time
6176
const pingTime = Date.now() - startTime;
62-
6377
// Return success response with database status
6478
res.status(200).json({
6579
status: "up",
6680
database: {
6781
connected: true,
68-
ping: pingTime,
82+
ping: `${pingTime}ms`,
6983
lastError: null,
7084
},
7185
});

0 commit comments

Comments
 (0)