From 88912c4c5034c84675a93b5ae582184df40ad909 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Thu, 4 Nov 2010 12:06:13 -0700 Subject: [PATCH] Started Express server --- Readme.md | 4 --- test/server.js | 68 ++++++++++++++++-------------------------- test/views/layout.jade | 6 ++++ test/views/tests.jade | 1 + 4 files changed, 32 insertions(+), 47 deletions(-) create mode 100644 test/views/layout.jade create mode 100644 test/views/tests.jade diff --git a/Readme.md b/Readme.md index c16bc68..97f84b0 100644 --- a/Readme.md +++ b/Readme.md @@ -83,10 +83,6 @@ Visual tests: $ node test/server.js -or provide a port: - - $ sudo node test/server.js 80 - ## License (The MIT License) diff --git a/test/server.js b/test/server.js index 217b9d6..ac466e4 100644 --- a/test/server.js +++ b/test/server.js @@ -3,46 +3,28 @@ * Module dependencies. */ -var http = require('http') - , fs = require('fs'); - -var args = process.argv.slice(2) - , port = args.length - ? parseInt(args[0], 10) - : 3000; - -var images = fs.readdirSync(__dirname + '/images').sort(); - -function list(images) { - return '' + images.map(function(path, i){ - if ('.gitignore' == path) return ''; - return '' - + '' - + '' - + '' - + ''; - }).join('') + '
TestReference
' + i + '
'; -} - -http.createServer(function(req, res){ - switch (req.url) { - case '/': - res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(list(images)); - break; - default: - fs.readFile(__dirname + '/' + req.url, function(err, buf){ - if (err || !buf) { - res.writeHead(404, { 'Content-Type': 'text/html' }); - res.end('

Not Found

'); - } else { - res.writeHead(200, { - 'Content-Type': 'image/png' - , 'Content-Length': buf.length - }); - res.end(buf); - } - }); - } -}).listen(port); -console.log('Test image server started on port ' + port); \ No newline at end of file +var express = require('../support/express') + , jade = require('../support/jade') + , app = express.createServer(); + +// Config + +app.register('.jade', jade); +app.set('views', __dirname + '/views'); +app.set('view engine', 'jade'); + +// Middleware + +app.use(express.favicon()); +app.use(express.logger({ format: '\x1b[90m:remote-addr\x1b[0m - \x1b[33m:method\x1b[0m :url :status \x1b[90m:response-timems\x1b[0m' })); +app.use(app.router); +app.use(express.errorHandler({ showStack: true })); + +// Routes + +app.get('/', function(req, res){ + res.render('tests'); +}); + +app.listen(3000); +console.log('Test server listening on port %d', app.address().port); \ No newline at end of file diff --git a/test/views/layout.jade b/test/views/layout.jade new file mode 100644 index 0000000..efa189a --- /dev/null +++ b/test/views/layout.jade @@ -0,0 +1,6 @@ +!!! +html + head + title node-canvas + body + != body diff --git a/test/views/tests.jade b/test/views/tests.jade new file mode 100644 index 0000000..339c457 --- /dev/null +++ b/test/views/tests.jade @@ -0,0 +1 @@ +h1 Tests \ No newline at end of file