Giter Site home page Giter Site logo

road's People

Contributors

kishorenc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

road's Issues

Pass req, res objects separately

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 reqand res as separate parameters. New method signature will look this way:

controllerMethod(req, res, callback)

Default routes should be internalized

Instead of making routes.js mandatory, it should be made optional, road should work with default route of /:controller?/:action?/:id? automatically.

Callback

Would be useful to have a callback(err, next) which road will call when it's done.

View callbacks look messy

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'});              

Handle errors

Errors should be passed down the stack using next(err).

Set status property on Error()

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.

JSON render support for callback

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'}});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.