From 1c10f8438c0f5357e6c902490340b2ebc85001eb Mon Sep 17 00:00:00 2001 From: mattx Date: Mon, 22 Jun 2020 16:50:50 +0200 Subject: [PATCH] add config functionality --- index.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.coffee b/index.coffee index 720e485..9b95efb 100644 --- a/index.coffee +++ b/index.coffee @@ -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)