Added json response to http get and added port var

This commit is contained in:
Arne van Iterson 2020-04-28 11:58:41 +02:00
parent 6965c823fc
commit 0096d47138
3 changed files with 9 additions and 31 deletions

View File

@ -1,4 +0,0 @@
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}

View File

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TanksJS-Server</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<h1>TanksJS-Server</h1>
</body>
</html>

View File

@ -2,11 +2,11 @@ var app = require("express")();
var http = require("http").createServer(app); var http = require("http").createServer(app);
var io = require("socket.io")(http); var io = require("socket.io")(http);
const port = 3000;
var colours = require("colors"); var colours = require("colors");
colours.enable(); colours.enable();
colours.setTheme({ colours.setTheme({
silly: "rainbow",
input: "grey",
verbose: "cyan", verbose: "cyan",
prompt: "grey", prompt: "grey",
info: "green", info: "green",
@ -23,19 +23,13 @@ const traffic = {
int: colours.data("-- ") int: colours.data("-- ")
}; };
var path = require("path");
// Send html & css files
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname + "/../html/index.html"));
});
app.get("/index.css", (req, res) => {
res.sendFile(path.join(__dirname + "/../css/index.css"));
});
var players = {}; var players = {};
// Send players json object
app.get("/", (req, res) => {
res.send(players);
});
// Handle Connection // Handle Connection
io.on("connection", (socket) => { io.on("connection", (socket) => {
// Handle disconnection // Handle disconnection
@ -124,6 +118,6 @@ io.on("connection", (socket) => {
}); });
}); });
http.listen(3000, () => { http.listen(port, () => {
console.log(colours.data("\nTanksJS-Server ready, listening on port 3000\n")); console.log(colours.data(`\nServer ready, listening on port ${port}\n`));
}); });