-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
67 lines (50 loc) · 1.6 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
57
58
59
60
61
62
63
64
65
66
67
const express = require("express");
const app = express();
const http = require("http");
const socketio = require("socket.io");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
var cors = require("cors");
require("dotenv/config");
const PORT = process.env.PORT || 5000;
// Middlewares - A mechanism to run a function when an endpoint is hit
// Everytime we go through any route, an authentication function is triggered
// app.use(auth);
// Import Routes
const postsRoute = require("./routes/postings");
const usersRoute = require("./routes/users");
const offeringsRoute = require("./routes/offerings");
const notificationsRoute = require("./routes/notifications");
const messagesRoute = require("./routes/messages");
const Socket = require("./socket/socket");
app.use(cors());
app.use(bodyParser.json({ limit: "50mb" }));
app.use("/api/postings", postsRoute);
app.use("/api/users", usersRoute);
app.use("/api/notifications", notificationsRoute);
app.use("/api/offerings", offeringsRoute);
app.use("/api/messages", messagesRoute);
// Routes
app.get("/", (req, res) => {
res.send("REST API for Tradeforce");
});
mongoose.set("useFindAndModify", false);
// Connect to DB
// User: testUser
// Pass: test123
mongoose.connect(
process.env.DB_CONNECTION,
{ useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true },
() => {
console.log("Connected to DB!");
}
);
const server = http.createServer(app);
Socket.setupSocket(
socketio(server, {
transports: ["websocket"],
})
);
server.listen(PORT, () => {
console.log(`Server listening on port ${PORT}.`);
});