-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
76 lines (55 loc) · 1.72 KB
/
Copy pathapp.js
File metadata and controls
76 lines (55 loc) · 1.72 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
74
75
76
import "dotenv/config";
import Fastify from "fastify";
import fastifySocketIO from "fastify-socket.io";
import { PORT } from "./src/config/config.js";
import { connectDB } from "./src/config/connect.js";
import { admin, buildAdminRouter } from "./src/config/setup.js";
import { registerRoutes } from "./src/routes/index.js";
const start = async ()=>{
await connectDB(process.env.MONGO_URI)
const app = Fastify()
app.register(fastifySocketIO,{
cors:{
origin:'*'
},
pingInterval:10000,
pingTimeout:5000,
transports:['websocket']
});
await registerRoutes(app)
await buildAdminRouter(app);
app.listen({port: PORT , host:'0.0.0.0',}, (err,addr)=>{
if(err){
console.log(err);
}
else{
console.log(`ZipZap Started on http://localhost:${PORT}${admin.options.rootPath}`);
}
})
app.ready().then(() => {
app.io.on("connection", (socket) => {
console.log("A User Connected ✅");
socket.on("joinRoom",(orderId)=>{
socket.join(orderId);
console.log(`🔴 User Joined room ${orderId}`);
})
socket.on('disconnect',()=>{
console.log(`User Disconnected ❌`);
})
});
});
}
start()
// export const authenticate = async (email, password) => {
// if (email && password) {
// const user = await Admin.findOne({ email });
// if (!user) {
// return null;
// }
// if (user.password === password) {
// return Promise.resolve({ email: email, password: password });
// } else {
// return null;
// }
// }
// };