-
Notifications
You must be signed in to change notification settings - Fork 8
Create app
- Create Default Application
- Create Application with Database
- Create Application with Theme
- Create Application with session
- Create Application with authorization
- Create Application with file Uploader
- Create Application with Recaptcha
- Create Application with Mailer
- Create Application with Shopping Cart
- Create Application with Socket.io
# 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
- Browse your application to http://localhost:3000
On initialization directories tree generated, like that
$ 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.
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.
# 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;
...
}
}
$ trinte -i HelloWorld --auth
- Add deps to
trinte-auth
,passport
andpassport-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
$ trinte -i HelloWorld --uploader
- Add deps to
express-uploader
,gm
andnode-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
$ 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
$ 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
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.
$ trinte -i HelloWorld --socket
- Rewrite file
/config/routes.js
- Add
<script src="/socket.io/socket.io.js"></script>
in toviews/_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;
...
}
}