Skip to content
Browse files

[example refactor v0.6] Make example work

Changes:

  * Remove `require.paths` and `sys` reference
  * `router.route` -> `router.handle`
  * Remove unused `path` `require`
  * Use `router.map`
  * Callbacks take (`req`, `res`), not just (`res`)
  • Loading branch information...
1 parent c6c05bd commit f2ce258fcb81a18918c8a80e5296f19aacf8dd88 @mmalecki mmalecki committed Oct 24, 2011
Showing with 11 additions and 10 deletions.
  1. +11 −10 example/http-server.js
View
21 example/http-server.js
@@ -1,16 +1,17 @@
-var path = require('path'),
- sys = require('sys');
+var util = require('util');
-require.paths.unshift(path.join(__dirname, '..', 'lib'));
-
-var journey = require('journey');
+var journey = require('../lib/journey');
//
// Create a Router object with an associated routing table
//
-var router = new(journey.Router)(function (map) {
- map.root.bind(function (res) { res.send("Welcome") }); // GET '/'
- map.get('/version').bind(function (res) {
+var router = new(journey.Router);
+
+router.map(function () {
+ this.root.bind(function (req, res) { // GET '/'
+ res.send(200, {}, "Welcome");
+ });
+ this.get('/version').bind(function (req, res) {
res.send(200, {}, { version: journey.version.join('.') });
});
});
@@ -23,11 +24,11 @@ require('http').createServer(function (request, response) {
//
// Dispatch the request to the router
//
- router.route(request, body, function (result) {
+ router.handle(request, body, function (result) {
response.writeHead(result.status, result.headers);
response.end(result.body);
});
});
}).listen(8080);
-sys.puts('journey listening at http://127.0.0.1:8080');
+util.puts('journey listening at http://127.0.0.1:8080');

0 comments on commit f2ce258

Please sign in to comment.
Something went wrong with that request. Please try again.