add config functionality

This commit is contained in:
mattx 2020-06-22 16:50:50 +02:00
parent 6a68f5b66b
commit 1c10f8438c
1 changed files with 10 additions and 3 deletions

View File

@ -1,9 +1,16 @@
fs = require "fs"
express = require "express"
app = express()
expressWs = require("express-ws")(app)
port = 3000
sockets = []
try
config = require("./config.js")
catch error
console.log "cannot find config, auto-creating"
sampleConfig = "var config = {};\nconfig.port = 3000;\nmodule.exports = config;\n"
fs.writeFileSync "./config.js", sampleConfig
config = {port: 3000}
# the counter itself
counter = 0
@ -32,5 +39,5 @@ app.ws "/api", (ws, req) ->
broadcastCounter() if not errored
ws.on "close", -> removeElement sockets, ws
app.listen port, () ->
console.log("ready on port " + port)
app.listen config.port, () ->
console.log("ready on port " + config.port)