-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (56 loc) · 1.67 KB
/
server.js
File metadata and controls
73 lines (56 loc) · 1.67 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
process.on("uncaughtException", (e) => {
console.log("Uncaught exception::" + e);
console.log("Process is exiting");
process.exit(1);
});
const http = require("http");
const app = require("./src/app");
const {
app: { port },
origin,
} = require("./src/config/config.app");
const server = http.createServer(app);
const io = require("socket.io")(server, {
cors: {
origin: `${origin}`,
},
debug: true,
});
const ConservationAssistant = require("./src/services/aiAssistant/conservation.assistant");
const EventEmitter = require("events");
const internalEvents = new EventEmitter();
internalEvents.setMaxListeners(50);
internalEvents.on("process:ai:message", async (data) => {
try {
const { message, conservationId } = data;
console.log("Processing AI message for conservation:", conservationId);
const aiResponse = await ConservationAssistant.processMessage(message, conservationId);
if (aiResponse) {
console.log("AI Assistant responded to message:", aiResponse._id);
}
} catch (error) {
console.error("Error processing AI message:", error);
}
});
global._internalEvents = internalEvents;
const serverInstance = server.listen(port, () => {
console.log("App start with port::" + port);
});
require("./src/socket/index")(io);
global._io = io;
process.on("unhandledRejection", (e) => {
console.log("Unhandled rejection::" + e);
console.log("Server is shutting down");
serverInstance.close(() => {
process.exit(1);
});
});
process.on("SIGINT", () => {
console.log("Ctrl c deteted app is closing");
serverInstance.close(() => {
console.log("Server closed");
process.exit(1);
});
});
module.exports = server;