Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kishorenc/road
base: f32bf6c19e
...
head fork: kishorenc/road
compare: de9edb99c5
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
27 README.md
@@ -1,11 +1,15 @@
#Road - route helper for Express
-A route helper for express that allows you to map routes, controllers and views by following logical conventions. See example application for use cases. You need express 2.x and ejs available to run the example.
+A route helper for express that allows you to map routes, controllers and views by following logical conventions. See example application for use cases. You need Express 3.x or Express 2.x and ejs available to run the example.
##Installation
npm install road
+## Express 3.x
+
+The following guide is for Express 3.x. If you using Express 2.x, please refer to the `0.3` branch for instructions.
+
##Features
* Wire your routes to individual controllers and views using convention
@@ -13,10 +17,13 @@ A route helper for express that allows you to map routes, controllers and views
* Serve the views in custom MIME types
* View helper for serving JavaScript objects as application/json
-##Comptability
+##Compatibility
+
+ * Tested with Express 3.x and Express 2.x
- * Works on both node 0.4.x and 0.6.x
- * Tested with Express 2.5.x
+##v0.4.0
+
+Road 0.4.x is compatible with Express 3.x. Road also works on Express 2.x, but you have to check the `0.3` branch for instructions.
##Changes in v0.3.x
@@ -26,13 +33,15 @@ See example application for complete use cases.
##Quick Start
-Integrating Road with your Express application is really simple. Tell Express to let Road handle the routing this way:
+Integrating Road with your Express application is really simple.
``` javascript
-var road = require('road');
+// create an express app
+var app = express();
-// mount application routes using road
-app.use(express.router(road));
+// initialize road this way
+var road = require('road');
+road(app);
```
Road, by convention, expects you to drop your controllers into the `controllers` folder in your application root.
@@ -233,7 +242,7 @@ Run the tests from the test folder this way:
(The MIT License)
-Copyright (c) 2011 Kishore Nallan <kishore@kishorelive.com>
+Copyright (c) 2011-2012 Kishore Nallan <kishore@kishorelive.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
12 example/app.js
@@ -5,8 +5,7 @@
var express = require('express'),
road = require('road');
- app = express.createServer();
-
+ app = express();
road.configure({
viewEngine: 'ejs',
@@ -19,9 +18,12 @@ app.configure(function() {
app.use(express.static(__dirname+'/public'));
app.use(express.bodyParser());
app.use(express.methodOverride());
- app.use(express.router(road));
+ app.use(app.router);
+ app.use(onError);
});
+// initialize road
+road(app);
function roadCallback(err, req, res, next) {
console.log(err, req, res, next);
@@ -30,9 +32,9 @@ function roadCallback(err, req, res, next) {
// else do something, maybe invoke the next middleware...
}
-app.error(function(err, req, res, next){
+function onError(err, req, res, next){
console.error(err+err.message+err.stack);
res.send('Error, or not found.');
-});
+};
module.exports = app;
View
4 lib/road.js
@@ -2,7 +2,7 @@ var fs = require('fs');
var config = {};
-exports.version = '0.3.4';
+exports.version = '0.4.0';
var road = module.exports = function(app) {
for (var index in config.routes) {
@@ -94,7 +94,7 @@ function redirectOrRenderPlain(req, res, view, viewData, next) {
switch(cType) {
case 'redirect':
if(!viewData || viewData !== 301) viewData = 302;
- res.redirect(view[cType], viewData);
+ res.redirect(viewData, view[cType]);
handleCallback(null, req, res, next);
break;
default:
View
4 package.json
@@ -1,6 +1,6 @@
{
"name": "road",
- "version": "0.3.4",
+ "version": "0.4.0",
"description": "A route helper for express.",
"homepage": "https://github.com/kishorenc/road",
"author": "Kishore Nallan <kishore@kishorelive.com>",
@@ -15,7 +15,7 @@
"ejs": "*",
"mocha": "*",
"request": "*",
- "express": "2.5.4"
+ "express": "3.x"
},
"bugs": {
"mail": "kishore@kishorelive.com",
View
35 test/test.js
@@ -5,6 +5,7 @@ var road = require('../'),
request = require('request'),
assert = require('assert');
+var server;
var port = 3456,
rootUrl = 'http://localhost:3456/';
@@ -22,11 +23,11 @@ afterEach(function() {
describe('Routing with GET', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('should call index method of index controller', function(done){
@@ -69,11 +70,11 @@ describe('Routing with GET', function() {
describe('Custom URL mapping defined in routes.js', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('should GET /customPath', function(done) {
@@ -107,11 +108,11 @@ describe('Custom URL mapping defined in routes.js', function() {
describe('POST, PUT & DELETE using req.params.id', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('returns the :id sent to it via POST', function(done) {
@@ -146,11 +147,11 @@ describe('POST, PUT & DELETE using req.params.id', function() {
describe('Content Types', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('should serve a view with custom MIME type (text/plain)', function(done) {
@@ -186,12 +187,12 @@ describe('Handle undefined routes', function() {
before(function() {
console.error = function() {};
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
console.error = consoleError;
- app.close();
+ server.close();
});
it('should return an error when an non-existent controller is called', function(done) {
@@ -216,12 +217,12 @@ describe('Handle undefined routes', function() {
describe('Callback passed to road', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
console.error = consoleError;
- app.close();
+ server.close();
});
it('should invoke the callback after view rendering is done', function(done) {
@@ -251,11 +252,11 @@ describe('Callback passed to road', function() {
describe('Redirection', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('should redirect by default returns 302 as status code', function(done) {
@@ -303,11 +304,11 @@ describe('Redirection', function() {
describe('Content negotiation', function() {
before(function() {
- app.listen(port);
+ server = app.listen(port);
});
after(function() {
- app.close();
+ server.close();
});
it('should return JSON response', function(done) {
@@ -340,4 +341,4 @@ describe('Content negotiation', function() {
};
request(rootUrl+'foo/contentNegotiation.txt');
});
-});
+});

No commit comments for this range

Something went wrong with that request. Please try again.