forked from arne/TanksJS-Server
Added json response to http get and added port var
This commit is contained in:
parent
6965c823fc
commit
0096d47138
@ -1,4 +0,0 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
text-align: center;
|
||||
}
|
@ -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>
|
24
src/index.js
24
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`));
|
||||
});
|
Loading…
Reference in New Issue
Block a user