Fixed so io is being sent in a better manner, and listening on the same port as the rest
This commit is contained in:
@@ -5,7 +5,7 @@ const mongoose = require("mongoose");
|
|||||||
mongoose.connect("mongodb://localhost:27017/vinlottis", {
|
mongoose.connect("mongodb://localhost:27017/vinlottis", {
|
||||||
useNewUrlParser: true
|
useNewUrlParser: true
|
||||||
});
|
});
|
||||||
const io = require("socket.io")(8080);
|
let io;
|
||||||
const mustBeAuthenticated = require(path.join(
|
const mustBeAuthenticated = require(path.join(
|
||||||
__dirname + "/../middleware/mustBeAuthenticated"
|
__dirname + "/../middleware/mustBeAuthenticated"
|
||||||
));
|
));
|
||||||
@@ -68,7 +68,6 @@ router.route("/winner").get(mustBeAuthenticated, async (req, res) => {
|
|||||||
colorToChoseFrom = "yellow";
|
colorToChoseFrom = "yellow";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.emit("color_winner", { color: colorToChoseFrom });
|
io.emit("color_winner", { color: colorToChoseFrom });
|
||||||
|
|
||||||
findObject[colorToChoseFrom] = { $gt: 0 };
|
findObject[colorToChoseFrom] = { $gt: 0 };
|
||||||
@@ -169,7 +168,6 @@ router.route("/attendee").post(mustBeAuthenticated, async (req, res) => {
|
|||||||
yellow,
|
yellow,
|
||||||
phoneNumber: attendee.phoneNumber
|
phoneNumber: attendee.phoneNumber
|
||||||
});
|
});
|
||||||
console.log(newAttendee);
|
|
||||||
await newAttendee.save();
|
await newAttendee.save();
|
||||||
|
|
||||||
io.emit("new_attendee", {});
|
io.emit("new_attendee", {});
|
||||||
@@ -177,4 +175,7 @@ router.route("/attendee").post(mustBeAuthenticated, async (req, res) => {
|
|||||||
res.send(true);
|
res.send(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = function(_io) {
|
||||||
|
io = _io;
|
||||||
|
return router;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const server = require("http").Server(app);
|
||||||
|
const io = require("socket.io")(server);
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const session = require("express-session");
|
const session = require("express-session");
|
||||||
const User = require(path.join(__dirname + "/schemas/User"));
|
const User = require(path.join(__dirname + "/schemas/User"));
|
||||||
@@ -83,7 +85,7 @@ app.use("/", loginApi);
|
|||||||
app.use("/api/", updateApi);
|
app.use("/api/", updateApi);
|
||||||
app.use("/api/", retrieveApi);
|
app.use("/api/", retrieveApi);
|
||||||
app.use("/api/", wineinfoApi);
|
app.use("/api/", wineinfoApi);
|
||||||
app.use("/api/virtual/", virtualApi);
|
app.use("/api/virtual/", virtualApi(io));
|
||||||
app.use("/subscription", subscriptionApi);
|
app.use("/subscription", subscriptionApi);
|
||||||
|
|
||||||
app.get("/dagens", function(req, res) {
|
app.get("/dagens", function(req, res) {
|
||||||
@@ -94,4 +96,4 @@ app.use("/service-worker.js", function(req, res) {
|
|||||||
res.sendFile(path.join(__dirname, "public/sw/serviceWorker.js"));
|
res.sendFile(path.join(__dirname, "public/sw/serviceWorker.js"));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(30030);
|
server.listen(30030);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.getAttendees();
|
this.getAttendees();
|
||||||
this.getWinners();
|
this.getWinners();
|
||||||
this.socket = io(window.location.hostname + ":8080");
|
this.socket = io(`${window.location.hostname}:${window.location.port}`);
|
||||||
this.socket.on("color_winner", msg => {
|
this.socket.on("color_winner", msg => {
|
||||||
this.currentWinnerDrawn = true;
|
this.currentWinnerDrawn = true;
|
||||||
this.currentWinnerColor = msg.color;
|
this.currentWinnerColor = msg.color;
|
||||||
|
|||||||
Reference in New Issue
Block a user