-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
56 lines (48 loc) · 1.37 KB
/
app.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
const express = require("express");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const helmet = require("helmet");
const morgan = require("morgan");
const socketio = require("socket.io");
const http = require("http");
const userRouter = require("./routes/user.route");
const newsRouter = require("./routes/news.route");
const auctionRouter = require("./routes/auction.route");
// const User = require("./database/models/user.model");
const path = require("path");
require("dotenv").config();
require("./database/connection");
const app = express();
const server = http.createServer(app);
const io = socketio(server, {
cors: {
origin: "http://localhost:3000",
credentials: true,
},
});
//Middleware
app.use(cookieParser());
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(helmet({ contentSecurityPolicy: false }));
app.use(morgan("dev"));
app.use(express.json());
//Routes
app.use(userRouter);
app.use(newsRouter);
app.use(auctionRouter);
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
require("./routes/socket.route")(io);
server.listen(process.env.PORT || 8000, () => {
//User.collection.deleteMany({});
console.log("Listening on port 8000");
});