X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-cgt.git;a=blobdiff_plain;f=server.coffee;h=8e35241193658495fe4e01b6829920299ff7bbea;hp=b1cdac9c95fa437ac130866ec311f254ec9b9ca0;hb=9a036497fdd48b07f12f9d8172eeaabc2373cb64;hpb=8c6e422dbf34db0f751e392e2e9d86fcdedf4aa7 diff --git a/server.coffee b/server.coffee index b1cdac9..8e35241 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 = process.env.app_port ? 9988 +listen_port = process.env.PORT ? process.env.app_port ? 9988 sys = require 'sys' fs = require 'fs' http = require 'http' @@ -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,15 +274,15 @@ 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 else if rel_path.substr(rel_path.length - 3) is '.js' res.writeHead 200, 'Content-Type': 'text/javascript' return js_handler url_parts.query, res, req, url_parts - else if rel_path.substr(rel_path.length - 4) is '/set' + else if rel_path is 'set' data = '' req.on 'data', (chunk) -> data += chunk @@ -293,7 +293,7 @@ http_server = http.createServer (req, res) -> query[key] = parg return set_handler query, res, req, url_parts return - else if rel_path.substr(rel_path.length - 4) is '/get' + else if rel_path is 'get' return get_handler url_parts.query, res, req, url_parts else if rel_path.substr(rel_path.length - 4) is '.ico' res.writeHead 404 @@ -302,11 +302,10 @@ 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' +# make sure the current working directory is correct +process.chdir __dirname setInterval expire_old_games, 2 * 60 * 1000 # check every 2 minutes for expired games -http_server.listen listen_port, "127.0.0.1" +http_server.listen listen_port console.log "Server running at http://127.0.0.1:#{listen_port}/"