kishorenc / road Goto Github PK
View Code? Open in Web Editor NEWRoute helper for Express
License: MIT License
Route helper for Express
License: MIT License
The controller methods current take conn
as the first parameter. To access req
and res
we need to do conn.req
and conn.res
.
No idea how I ended up dong this. Pass req
and res
as separate parameters. New method signature will look this way:
controllerMethod(req, res, callback)
Instead of making routes.js
mandatory, it should be made optional, road should work with default route of /:controller?/:action?/:id?
automatically.
Something along the lines of callback('redirect', 'url') will be nice.
Would be useful to have a callback(err, next)
which road will call when it's done.
The callback
of the controller method is used to render the view. It offers lots of options, but ends up looking unwieldy at times. Also, does not follow node's convention of (err, data).
Example:
callback(['viewName', {key:'value'}], 'text/plain');
Redesigned callbacks should look like:
// render view with data (optional) and MIME type (optional)
callback(err, 'viewName', {key: 'value'}, 'text/plain');
// render view with just data and MIME type
callback(err, 'viewName`, 'text/plain');
// render plain text string in custom MIME type
callback(err, {'text/plain': 'plain text string'});
i.e. NOT bookController
- should be BookController
?
I am not sure about the convention, something to think about.
Errors should be passed down the stack using next(err)
.
In handleCallback()
.
Road currently passes any error encountered (or passed from controller) down stack. Useful to add a status
property to error object to indicate type of error - this can be used to render the correct HTTP status code by the downstream error handling function.
E.g. if controller is not found, set error.status = 404, for other errors prob set status to 500.
Currently, to render JSON through the callback, need to do something like this:
var jsonMsg = JSON.stringify({
code : -4,
message : response
});
return callback(null, {'text/plain': jsonMsg});
Verbose. Make it do something like:
callback(null, {'json': {foo: 'bar'}});
Generators for quickly creating stub controllers and corresponding view folders from the command line.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.