-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (30 loc) · 912 Bytes
/
Copy pathserver.js
File metadata and controls
35 lines (30 loc) · 912 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
31
32
33
34
35
import fastify from "fastify";
import dotenv from "dotenv";
import cors from "@fastify/cors";
import responseRoute from "./AI/route/ResponseRoute.js";
import nodeCron from "node-cron";
import axios from "axios";
dotenv.config();
const PORT = process.env.PORT || 3000;
const app = fastify();
app.register(cors);
app.register(responseRoute, { prefix: '/api/v1/ai' });
const start = async () => {
try {
await app.listen({ port: PORT, host: '0.0.0.0' });
console.log(`Server is running on port ${PORT}`);
} catch (err) {
console.error(err);
process.exit(1);
}
}
const serverUrl = "https://milobrain.onrender.com";
nodeCron.schedule("*/10 * * * *", async () => {
try {
await axios.get(serverUrl);
console.log("Pinged server to keep it awake");
} catch (error) {
console.error("Failed to ping server:", error.message);
}
})
start();