X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=server.coffee;h=b1cdac9c95fa437ac130866ec311f254ec9b9ca0;hb=8c6e422dbf34db0f751e392e2e9d86fcdedf4aa7;hp=f0ebddf7d92a4da934c9f781dc601199ef0a9a3e;hpb=17ee6e1dba95f184fa1cdf66b4db3153b350e757;p=peach-cgt.git diff --git a/server.coffee b/server.coffee index f0ebddf..b1cdac9 100644 --- a/server.coffee +++ b/server.coffee @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -listen_port = 13850 +listen_port = process.env.app_port ? 9988 sys = require 'sys' fs = require 'fs' http = require 'http' @@ -26,7 +26,7 @@ model = require './common.coffee' games = {} max_concurrent_games = 50 -max_game_idle = 2 * 60 * 60 * 1000 # two hours (in miliseconds) +max_game_idle = 3 * 60 * 60 * 1000 # three hours (in miliseconds) # timeout function with args in convenient order timeout = (ms, func) -> setTimeout func, ms @@ -104,7 +104,7 @@ js_handler = (args, out, request, url_parts) -> html_handler = (args, out, request, url_parts) -> fs.readFile 'index.html', 'utf8', (err, data) -> if err - return out.end 'Server failed to read index.html' + return out.end "Server failed to read index.html: #{err}" out.end data clean_pathname_regex = new RegExp('[^a-zA-Z/_.-]') @@ -301,6 +301,11 @@ http_server = http.createServer (req, res) -> return html_handler url_parts.query, res, req, url_parts +################## INIT #################### +# nodester starts this app with the current working directory set to / and working copy in /app +if process.cwd() is '/' + process.chdir '/app' + setInterval expire_old_games, 2 * 60 * 1000 # check every 2 minutes for expired games http_server.listen listen_port, "127.0.0.1"