Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactoring and house keeping

  • Loading branch information...
commit cfde8d4b4b692d9d192462274cbad2b5c99863d1 1 parent 3c09057
@icodejs authored
Showing with 13 additions and 11 deletions.
  1. +13 −11 server.js
View
24 server.js
@@ -11,12 +11,13 @@ http.createServer(function (req, res) {
var pathname = url.parse(req.url, true).pathname,
query = url.parse(req.url, true).query,
method = req.method,
- output = '';
+ output = '',
+ paths = pathname.split('/');
if (pathname === '/') {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World icodejs\n');
- } else if (pathname.indexOf('mb') && query.url) {
+ } else if (paths.length > 1 && paths[1] === 'md' && query.url) {
var json = '';
if (query.url.indexOf('http://') === -1) {
@@ -27,19 +28,17 @@ http.createServer(function (req, res) {
html: query.url,
src: [jquery],
done: function (errors, window) {
+ if (errors) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('[{"error": "' + errors.toString() + '"}]');
+ return;
+ }
+
var i,
len,
err_text = '',
$ = window.$;
- if (errors && errors.length > 0) {
- for (i = 0, len = errors.length; i < len; i += 1) {
- err_text += errors[i] + ' | '
- }
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('[{"error": "' + err_text + '"}]');
- }
-
$('a, img').each(function () {
var that = $(this),
url = that.attr('href') || that.attr('src');
@@ -72,7 +71,10 @@ http.createServer(function (req, res) {
res.end(output);
}
}); // end jsdom
+ } else {
+ res.writeHead(404, {'Content-Type': 'text/plain'});
+ res.end('Error: not found!');
}
}).listen(80); //.listen(80);
-console.log('http://localhost:8080/');
+//console.log('http://localhost:8080/');
Please sign in to comment.
Something went wrong with that request. Please try again.