-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (45 loc) · 1.66 KB
/
main.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
//-------- DEPENDENCIES --------
const dotenv = require("dotenv").config();
const envConfig = require("./envConfig");
const express = require("express");
const compression = require("compression");
const { Server: IOServer } = require("socket.io");
const { Server: HttpServer } = require("http");
//------- MODULES --------
const mainRouter = require("./routers/mainRouter.js");
const chatRouter = require("./routers/chatRouter.js");
const cartRouter = require("./routers/cartRouter.js");
const adminRouter = require("./routers/adminRouter.js");
const randomRouter = require("./routers/randomRouter.js");
const mainSocket = require("./operative/socketIO.js");
const apiRouter = require("./routers/apiRouterProducts.js");
const apiRouterCart = require("./routers/apiRouterCart.js");
//------- APP -------
const app = express();
const httpServer = new HttpServer(app);
const io = new IOServer(httpServer);
const PORT = envConfig.port;
//-------- TEMPLATE GENERATOR --------
app.set("view engine", "ejs");
app.set("views", "./views");
//------- MIDDLEWARES ---------
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/", mainRouter);
app.use("/chat", chatRouter);
app.use("/cart", cartRouter);
app.use("/admin", adminRouter);
app.use("/random", randomRouter);
app.use("/api/productos", apiRouter);
app.use("/api/carrito", apiRouterCart);
app.use(express.static("./public"));
//-------- APP LISTEN --------
httpServer
.listen(PORT, () => {
console.log(`Server ready and listening on port ${PORT}.`);
})
.on("err", (err) => {
console.error(`Error in the server: \n { ${{ err }}`);
});
io.on("connection", mainSocket);