Permalink
Browse files

Big simplification of server.js thanks to express.js. No longer manua…

…lly defining static types and such.
  • Loading branch information...
1 parent 3f26923 commit a426ae42da2de0aebaacfe17a947f50a88093cf5 @akavlie committed Nov 8, 2011
Showing with 13 additions and 34 deletions.
  1. +13 −34 server.js
View
@@ -1,41 +1,20 @@
-var server = require('http').createServer(handler),
- io = require('socket.io').listen(server),
- fs = require('fs'),
- url = require('url'),
+var express = require('express'),
+ app = express.createServer(),
+ io = require('socket.io').listen(app),
irc = require('irc');
-var HOST = 'localhost',
- PORT = 12445;
+app.configure(function() {
+ app.use(express.static(__dirname + '/'));
+ app.use(express.static(__dirname + '/js'));
+ app.use(express.static(__dirname + '/images'));
+ app.listen(8337);
+});
-// HTTP handler
-function handler(req, res) {
- path = url.parse(req.url).pathname;
- if (path === '/') path = '/index.html'
+app.configure('production', function() {
+ app.listen(12445);
+});
- // Set content type
- var type = '';
- if (path.substr(-3) === '.js')
- type = 'text/javascript';
- else if (path.substr(-4) === '.css')
- type = 'text/css';
- else if (path.substr(-4) === '.png')
- type = 'image/png';
- else
- type = 'text/html';
-
- fs.readFile(__dirname + path, function (err, data) {
- if (err) {
- res.writeHead(500);
- return res.end('Error loading index.html');
- }
-
- res.writeHead(200, {'Content-Type': type});
- res.end(data);
- });
-}
-
-server.listen(PORT, HOST);
-console.log('Server running at http://' + HOST + ':' + PORT);
+console.log('Express server started on port %s', app.address().port);
// Socket.IO

0 comments on commit a426ae4

Please sign in to comment.