-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (45 loc) · 1.61 KB
/
server.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
const express = require("express");
const dotenv = require("dotenv");
const cors = require("cors");
const path = require("path");
const app = express();
const { authSocket, socketServer } = require("./socketServer");
const posts = require("./routes/posts");
const users = require("./routes/users");
const comments = require("./routes/comments");
const messages = require("./routes/messages");
const connectToDatabase = require("./db");
const PostLike = require("./models/PostLike");
const Post = require("./models/Post");
dotenv.config();
const httpServer = require("http").createServer(app);
const io = require("socket.io")(httpServer, {
cors: {
origin: ["http://localhost:3000", "https://post-it-jt47.onrender.com/","https://nullhawk.github.io/post-it/", "https://nullhawk.github.io","https://nullhawk-post-it.netlify.app"], //to change with hosting url
},
});
io.use(authSocket);
io.on("connection", (socket) => socketServer(socket));
// mongoose.connect(
// process.env.MONGO_URI,
// { useNewUrlParser: true, useUnifiedTopology: true },
// () => {
// console.log("MongoDB connected");
// }
// );
connectToDatabase();
httpServer.listen(process.env.PORT || 4000, () => {
console.log("Listening");
});
app.use(express.json());
app.use(cors());
app.use("/api/posts", posts);
app.use("/api/users", users);
app.use("/api/comments", comments);
app.use("/api/messages", messages);
// if (process.env.NODE_ENV == "production") {
// app.use(express.static(path.join(__dirname, "/client/build")));
// app.get("*", (req, res) => {
// res.sendFile(path.join(__dirname, "client/build", "index.html"));
// });
// }