Create app

Alexey Gordeyev edited this page Apr 17, 2015 · 40 revisions

Back to Documentation

Table of contents

Create Default Application

      # Create application
      $ trinte -i HelloWorld     
      # intall dependencies              
      $ cd HelloWorld && npm -l install        

      # generate scaffold
      $ trinte -g crud User active:bool name email password
      # running server
      $ trinte -s                              

On initialization directories tree generated, like that

Create Application with database

  $ trinte -i HelloWorld  --db sqlite3:./db/main.sqlite
  • Add deps to database driver module
  • Rewrite file /config/database.js
module.exports = {
    db: {
        driver     : "sqlite3",
        database   : "./db/main.sqlite"
    }
};

For more information about the configuration of access to the database server, see here.

Create Application with Theme

Available 9 themes default, cerulean, cosmo, cyborg, flatly, united, yeti, simplex, sandstone. Default theme default.

      # add `--theme` argument
      $ trinte -i HelloWorld --theme cosmo

See themes here.

Create Application with Session

      # add `--sess` argument
      $ trinte -i HelloWorld --sess

Will be the following changes:

  • Add deps to connect-caminte module
  • Rewrite file /config/session.js code here

access to session data from the controller:

module.exports = {
    ...
    'index': function(req, res, next) {
         var sess = req.session;
         ...
    }
}

Create Application with Authorization

  $ trinte -i HelloWorld  --auth
  • Add deps to trinte-auth, passport and passport-local modules
  • Add file /config/authorization/local.js code here
  • Rewrite file /config/routes.js
var Auth = require('./authorization/local'); 

module.exports = function routes(map, app) { 

    // default login page
    map.all( "/login", "apps#login" );
    // default logout route
    map.all( "/logout", Auth.logOut( '/' ) );

    // adding Auth middleware examples:

    // for Named routes
    map.get('/post/:id', 'posts#show', [Auth.isLoggedIn( '/login')]);

    // for Singleton resources
    map.resources( "posts", {
        middleware: [Auth.isLoggedIn( '/login')]
    });

    // for Namespaces
    map.namespace('api', {
        middleware: [Auth.isLoggedIn( '/login')]
    }, function (api) {
        api.resources("fligths");
        api.resources("airports");
        ...
    });
});

For more information about of routing, see here

Create Application with Uploader

  $ trinte -i HelloWorld  --uploader
  • Add deps to express-uploader, gm and node-uuid modules
  • Add file /config/addons/uploader.js code here
  • Rewrite file /config/routes.js
var Uploader = require('./addons/uploader');

module.exports = function routes(map, app) { 

    map.post('/uploading', Uploader.middleware());

});

For more information about the configuration of uploader, see here

Create Application with Recaptcha

  $ trinte -i HelloWorld  --recaptcha
  • Add deps to recaptcha module
  • Add file /config/addons/recaptcha.js code here
  • Rewrite file /config/routes.js
var Recaptcha = require('./addons/recaptcha');

module.exports = function routes(map, app) { 
    /**
     * recapcha middleware usage Recaptcha.middleware()
     **/
});

access to recaptcha from the controller:

module.exports = {
    ...
    'index': function(req, res, next) {
         var recaptcha = req.locals.recaptcha;
         ...
    }
}

For more information about the configuration of recaptcha, see here

Create Application with Mailer

  $ trinte -i HelloWorld  --mailer
  • Add deps to nodemailer module
  • Add file /config/addons/mailer.js code here
  • Rewrite file /config/routes.js
var Mail = require('./addons/mailer');

module.exports = function routes(map, app) { 

    map.post('/sendmail', Mail.mailSender());

});

For more information about the configuration of nodemailer, see here

Create Application with Shopping Cart

Session required.

  $ trinte -i HelloWorld  --cart
  • Add file /config/addons/cart.js code here
  • Rewrite file /config/routes.js
var Cart = require('./addons/cart');

module.exports = function routes(map, app) { 

    map.get('/cart', Cart.getProductFromCart());
    map.post('/cart', Cart.addProductToCart());

});

access to cart data from the controller:

module.exports = {
    ...
    'index': function(req, res, next) {
         var cart = req.session.cart;
         ...
    }
}

access to cart data from the view use cart variable.

Create Application with Socket support

  $ trinte -i HelloWorld  --socket
  • Rewrite file /config/routes.js
  • Add <script src="/socket.io/socket.io.js"></script> in to views/_layout.ejs
module.exports = function routes(map, app) { 

       app.io.on('connection', function (socket) {
          if (config.debug) console.log('a client connected');
          socket.on('disconnect', function () {
             if (config.debug) console.log('client disconnected');
          });
       });

});

access to socket from the controller:

module.exports = {
    ...
    'index': function(req, res, next) {
         var socket = req.app.io;
         ...
    }
}

Back to Documentation

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.