aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Kavlie <akavlie@gmail.com>2011-11-07 23:26:17 -0700
committerAaron Kavlie <akavlie@gmail.com>2011-11-07 23:26:17 -0700
commita426ae42da2de0aebaacfe17a947f50a88093cf5 (patch)
treeb5ed38bf77720137cac212c24835980c15511c05
parent3f26923dbef4ea367bc0db3b2bc2c13ff9ffc6b6 (diff)
downloadreevo-webirc-a426ae42da2de0aebaacfe17a947f50a88093cf5.tar.gz
reevo-webirc-a426ae42da2de0aebaacfe17a947f50a88093cf5.zip
Big simplification of server.js thanks to express.js. No longer manually defining static types and such.
-rw-r--r--server.js47
1 files changed, 13 insertions, 34 deletions
diff --git a/server.js b/server.js
index 6fb0aed..5192e94 100644
--- a/server.js
+++ b/server.js
@@ -1,41 +1,20 @@
1var server = require('http').createServer(handler), 1var express = require('express'),
2 io = require('socket.io').listen(server), 2 app = express.createServer(),
3 fs = require('fs'), 3 io = require('socket.io').listen(app),
4 url = require('url'),
5 irc = require('irc'); 4 irc = require('irc');
6 5
7var HOST = 'localhost', 6app.configure(function() {
8 PORT = 12445; 7 app.use(express.static(__dirname + '/'));
8 app.use(express.static(__dirname + '/js'));
9 app.use(express.static(__dirname + '/images'));
10 app.listen(8337);
11});
9 12
10// HTTP handler 13app.configure('production', function() {
11function handler(req, res) { 14 app.listen(12445);
12 path = url.parse(req.url).pathname; 15});
13 if (path === '/') path = '/index.html'
14 16
15 // Set content type 17console.log('Express server started on port %s', app.address().port);
16 var type = '';
17 if (path.substr(-3) === '.js')
18 type = 'text/javascript';
19 else if (path.substr(-4) === '.css')
20 type = 'text/css';
21 else if (path.substr(-4) === '.png')
22 type = 'image/png';
23 else
24 type = 'text/html';
25
26 fs.readFile(__dirname + path, function (err, data) {
27 if (err) {
28 res.writeHead(500);
29 return res.end('Error loading index.html');
30 }
31
32 res.writeHead(200, {'Content-Type': type});
33 res.end(data);
34 });
35}
36
37server.listen(PORT, HOST);
38console.log('Server running at http://' + HOST + ':' + PORT);
39 18
40 19
41// Socket.IO 20// Socket.IO