-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
32 lines (25 loc) · 807 Bytes
/
server.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
const express = require("express");
const path = require("path");
const WebSocket = require("ws");
const SocketClass = require("./Classes/SocketClass");
const app = express();
const socketServer = new WebSocket.Server({ port: 8080 });
const _socket = new SocketClass(socketServer, WebSocket);
/**
* Establish initial connection
* to websocket server and perform abstructed operations
*/
_socket.onConnected();
/**
* Enable frontend static file access
*/
app.use("/static", express.static("./public/static"));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public/views/index.html"));
});
// production best practice (using process.env)
const PORT = process.env.PORT || 5000;
// Listen for port connection
app.listen(PORT, () => {
console.log(`Running on port ${PORT}`);
});