X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=server.coffee;h=04116575226fcdf7e2ea78d88b70790a0b890b5b;hb=6c7d84c807fbc385902759c61517c738c390b690;hp=44084e8972c85f259d286cc45d3618b1383eb89d;hpb=6dafce4f87485fbc4ba2c06de1016ae5ba7b9bd7;p=peach-cgt.git diff --git a/server.coffee b/server.coffee index 44084e8..0411657 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' @@ -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/_.-]') @@ -115,9 +115,9 @@ clean_pathname = (str) -> str = str.replace clean_pathname_regex2, '/_' return str.replace clean_pathname_regex3, '_' -# serve javascript files from within /usr/share/javascript -javascript_handler = (args, out, request, url_parts) -> - filename = clean_pathname "/usr/share/#{url_parts.pathname}" +# serve javascript files from within external/ +external_javascript_handler = (args, out, request, url_parts) -> + filename = clean_pathname "external/#{url_parts.pathname.substr 10}" fs.readFile filename, 'utf8', (err, data) -> if err out.writeHead 404 @@ -274,8 +274,8 @@ http_server = http.createServer (req, res) -> rel_path = url_parts.pathname.substr 1 - if rel_path.substr(0, 11) is 'javascript/' - return javascript_handler url_parts.query, res, req, url_parts + if rel_path.substr(0, 9) is 'external/' + return external_javascript_handler url_parts.query, res, req, url_parts else if rel_path.substr(rel_path.length - 4) is '.css' res.writeHead 200, 'Content-Type': 'text/css' return css_handler url_parts.query, res, req, url_parts @@ -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"