-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
59 lines (49 loc) · 1.5 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
// DEPENDENCIES
const cors = require("cors");
const express = require("express");
// CONFIGURATION
const app = express();
const http = require("http").Server(app);
// MIDDLEWARE
app.use(express.json());
app.use(cors());
const socketIO = require("socket.io")(http, {
cors: {
origin: "http://localhost:3000",
},
});
//Add this before the app.get() block
socketIO.on("connection", (socket) => {
console.log(`⚡: ${socket.id} user just connected!`);
socket.on("disconnect", () => {
console.log("🔥: A user disconnected");
});
});
// CONTROLLERS
const bellsController = require("./controllers/bellsController.js");
const rewardsController = require("./controllers/rewardsController.js");
const usersController = require("./controllers/usersController.js");
const users_bellsController = require("./controllers/users_bellsController.js");
const users_rewardsController = require("./controllers/users_rewardsController.js");
app.use("/bells", bellsController);
app.use("/rewards", rewardsController);
app.use("/users", usersController);
app.use("/users_bells", users_bellsController);
app.use("/users_rewards", users_rewardsController);
// Allows requests from other origins (e.g. our REACT APP)
// PARSES JSON FOR US SO WE CAN USE IT.
// ROUTES
app.get("/", (req, res) => {
res.send("Welcome to WellBell!");
});
app.get("/api", (req, res) => {
res.json({
message: "Hello World",
});
});
//404 PAGE
app.get("*", (req, res) => {
res.status(404).send("PAGE NOT FOUND");
});
//EXPORT
module.exports = app;