From 0096d471382ee29224c907a9ed1710b0de7c2ac9 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Tue, 28 Apr 2020 11:58:41 +0200 Subject: [PATCH] Added json response to http get and added port var --- css/index.css | 4 ---- html/index.html | 12 ------------ src/index.js | 24 +++++++++--------------- 3 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 css/index.css delete mode 100644 html/index.html diff --git a/css/index.css b/css/index.css deleted file mode 100644 index c81e704..0000000 --- a/css/index.css +++ /dev/null @@ -1,4 +0,0 @@ -body { - font-family: Arial, Helvetica, sans-serif; - text-align: center; -} \ No newline at end of file diff --git a/html/index.html b/html/index.html deleted file mode 100644 index cb5cac3..0000000 --- a/html/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - TanksJS-Server - - - -

TanksJS-Server

- - \ No newline at end of file diff --git a/src/index.js b/src/index.js index a49f676..efa85fb 100644 --- a/src/index.js +++ b/src/index.js @@ -2,11 +2,11 @@ var app = require("express")(); var http = require("http").createServer(app); var io = require("socket.io")(http); +const port = 3000; + var colours = require("colors"); colours.enable(); colours.setTheme({ - silly: "rainbow", - input: "grey", verbose: "cyan", prompt: "grey", info: "green", @@ -23,19 +23,13 @@ const traffic = { 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 = {}; +// Send players json object +app.get("/", (req, res) => { + res.send(players); +}); + // Handle Connection io.on("connection", (socket) => { // Handle disconnection @@ -124,6 +118,6 @@ io.on("connection", (socket) => { }); }); -http.listen(3000, () => { - console.log(colours.data("\nTanksJS-Server ready, listening on port 3000\n")); +http.listen(port, () => { + console.log(colours.data(`\nServer ready, listening on port ${port}\n`)); }); \ No newline at end of file