-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·129 lines (105 loc) · 3.55 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Import the Express module
import express from "express";
// const hb = require("express-handlebars");
// Create a new instance of Express
const app = express();
// Import the AllthatStuff game file.
import game from "./game.js";
// connect MongoDB Atlas
// TODO:
// const mongoose = require('mongoose');
// const gameModel = require('./models/games');
// let secrets;
// if (process.env.NODE_ENV == "production") {
// secrets = process.env; // in prod the secrets are environment variables
// } else {
// secrets = require("./secrets"); // in dev they are in secrets.json which is listed in .gitignore
// }
// TODO:
// mongoose.connect(secrets.MONGO_URI, {
// useNewUrlParser: true,
// useUnifiedTopology: true
// })
// .then(() => {
// console.log('MongoDB Connected...');
// })
// .catch(err => console.log(err));
// this configures express to use express-handlebars:
// app.engine("handlebars", hb());
// app.set("view engine", "handlebars");
// Serve static html, js, css, and image files from the 'public' directory:
app.use(express.static("./public"));
app.get("/", function(req, res) {
res.sendFile(__dirname + "/public/index.html");
});
// app.get("/games", async (req, res) => {
// // res.sendFile(__dirname + "/public/games.html");
// // res.send('<h1>here you can see a list of all games played so far...</h1>');
// // TODO: create and import gameModel file and create handlebars for /games route
// const allGames = await gameModel.find({});
// try {
// console.log(allGames);
// res.render("allgames", {
// layout: "main",
// allGames
// });
// } catch (err) {
// console.log("err in allGames in /games: ", err);
// res.status(500).send(err);
// }
// });
// TODO: make this work:
// app.get('/games', function(req, res) {
// gameModel.find({}, {}, function(err, results) {
// if (err) {
// console.log(err);
// res.send([]);
// return;
// }
// console.log(results);
// res.send(results);
// // res.render("allgames", {
// // layout: "main",
// // allGames: results
// // });
// });
// });
app.get("/preview", function(req, res) {
res.sendFile(__dirname + "/public/preview/AllThatStuff_start-menu.png");
});
// TODO:
// const games = require("./controllers/controller.js");
// Create a new game entry
// app.post("/", games.create);
// ------------------------------------------
// // // Create a Node.js based http server on port 8080
// const server = require("http")
// .createServer(app)
// .listen(process.env.PORT || 8080, () =>
// console.log("port 8080 listening! - AllThatStuff")
// );
//
// // Create a Socket.IO server and attach it to the http server
// var io = require("socket.io").listen(server);
//
// // Listen for Socket.IO Connections. Once connected, start the game logic.
// io.sockets.on("connection", function(socket) {
// //console.log('client connected');
// game.initGame(io, socket);
// });
// ------------------------------------------
import http from "http";
const server = http.createServer(app);
import { Server as Io } from "socket.io";
const io = new Io(server, {
origins:
"localhost:8080 http://192.168.0.15:8080:* http://192.168.2.112:8080:* hhttps://all-that-stuff-v3.onrender.com:* www.allthatstuff.fun:*"
});
server.listen(process.env.PORT || 8080, () =>
console.log("port 8080 listening! - AllThatStuff")
);
// Listen for Socket.IO Connections. Once connected, start the game logic.
io.sockets.on("connection", function(socket) {
//console.log('client connected');
game.initGame(io, socket);
});