-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 1.21 KB
/
app.js
File metadata and controls
44 lines (37 loc) · 1.21 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
const express = require('express')
const cors = require("cors")
const { createServer } = require("http")
const { Server } = require("socket.io");
const dotenv = require("dotenv");
const registerChatHandler = require("./src/pipe/socketroom");
const dbconnect = require('./src/db/db_connect');
const { json } = require('express');
const userBase = require("./src/searchFeature/userBase");
dotenv.config()
const PORT = process.env.PORT;
const app = express();
const httpServer = createServer(app);
app.use(cors())
app.use(json())
app.use(express.urlencoded({extended:false}))
//db connection
dbconnect().then(() => console.log("db connected")).catch(err => console.log(err))
setInterval(() => {
userBase.updateUserBase()
}, 60000);
//express endpoints registry
app.get("/images/:name", (req, res) => {
res.status(200).sendFile(`${__dirname}/public/images/${req.params.name}`)
})
app.use("/auth",require("./src/pipe/auth"))
app.use("/chat",require("./src/pipe/chat"))
app.use("/search",require("./src/pipe/search"))
//Socket Registry
const io = new Server(httpServer, {
cors: {}
});
const onConnection = (socket) => {
registerChatHandler(io, socket)
}
io.on("connection", onConnection);
module.exports = httpServer