add config functionality
This commit is contained in:
parent
6a68f5b66b
commit
1c10f8438c
13
index.coffee
13
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user