-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (54 loc) · 1.76 KB
/
index.js
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 cors from "cors";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { config } from "dotenv";
// to get variables from .env
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
config({ path: join(__dirname, "./.env") });
import "./src/Models/db.js";
import bodyParser from "body-parser";
import { Sock } from "./src/sockets/Socket.mjs";
import { authRoute, userRoute, requestRoute ,uploadImagesRoute} from "./src/Routes/index.mjs";
// otpRoute
import express from "express";
const app = express();
import { createServer } from "http";
const httpServer = createServer(app);
import { Server } from "socket.io";
// import apiLimiter from "./src/Middleware/rateLimiting.mjs";
// config middleware cors
const io = new Server(httpServer, {
connectionStateRecovery: { maxDisconnectionDuration: 1000 },
});
export default io ;
// this to show the view chatForm file in home path
// app.use(
// cors({
// origin: 'http://localhost:5173',
// methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
// allowedHeaders: ['Content-Type', 'Authorization'],
// credentials: true
// })
// );
app.use(express.static("public"));
app.use(express.json());
app.use(bodyParser.json());
// Serve uploaded images
app.use("/uploads", express.static("./src/uploads"));
// const helmet = require('helmet');
// app.use(helmet());
app.get("/", function (req, res) {
res.json({
data: "home",
status: "200",
});
});
Sock(io);
// routes
// app.use("/api/v1/" , apiLimiter);
app.use("/api/v1/", authRoute, userRoute, requestRoute ,uploadImagesRoute);
//connect with socket.io server
httpServer.listen(process.env.PORT, () => {
console.log(`server is run in : http://localhost:${process.env.PORT}`);
});