-#!/usr/bin/env node
+#!/usr/bin/env nodejs
-var sys = require('sys'),
+var util = require('util'),
http = require('http'),
fs = require('fs'),
url = require('url'),
HttpServer.prototype.start = function(port) {
this.port = port;
this.server.listen(port);
- sys.puts('Http Server running at http://localhost:' + port + '/');
+ util.puts('Http Server running at http://localhost:' + port + '/');
};
HttpServer.prototype.parseUrl_ = function(urlString) {
if (req.headers['user-agent']) {
logEntry += ' ' + req.headers['user-agent'];
}
- sys.puts(logEntry);
+ util.puts(logEntry);
req.url = this.parseUrl_(req.url);
var handler = this.handlers[req.method];
if (!handler) {
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
- 'png': 'image/png'
+ 'png': 'image/png',
+ 'svg': 'image/svg+xml'
};
StaticServlet.prototype.handleRequest = function(req, res) {
res.write('<!doctype html>\n');
res.write('<title>Internal Server Error</title>\n');
res.write('<h1>Internal Server Error</h1>');
- res.write('<pre>' + escapeHtml(sys.inspect(error)) + '</pre>');
- sys.puts('500 Internal Server Error');
- sys.puts(sys.inspect(error));
+ res.write('<pre>' + escapeHtml(util.inspect(error)) + '</pre>');
+ util.puts('500 Internal Server Error');
+ util.puts(util.inspect(error));
};
StaticServlet.prototype.sendMissing_ = function(req, res, path) {
' was not found on this server.</p>'
);
res.end();
- sys.puts('404 Not Found: ' + path);
+ util.puts('404 Not Found: ' + path);
};
StaticServlet.prototype.sendForbidden_ = function(req, res, path) {
escapeHtml(path) + ' on this server.</p>'
);
res.end();
- sys.puts('403 Forbidden: ' + path);
+ util.puts('403 Forbidden: ' + path);
};
StaticServlet.prototype.sendRedirect_ = function(req, res, redirectUrl) {
'">here</a>.</p>'
);
res.end();
- sys.puts('301 Moved Permanently: ' + redirectUrl);
+ util.puts('301 Moved Permanently: ' + redirectUrl);
};
StaticServlet.prototype.sendFile_ = function(req, res, path) {