Permalink
Browse files

Code normalization, bug fixes.

  • Loading branch information...
1 parent b39b9b8 commit 77992184929e03e3345115169b344d8632b803c5 @outaTiME committed Nov 15, 2012
View
19 app.js
@@ -14,10 +14,6 @@ var
stylus = require('stylus'),
nib = require('nib'),
- // routes
- routes = require('./routes'),
- // user = require('./routes/user'),
-
// translation
i18n = require('i18next'),
@@ -55,7 +51,7 @@ app.configure(function () {
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(stylus.middleware({
- src: path.join(__dirname),
+ src: path.join(__dirname, 'assets'),
dest: path.join(__dirname, 'public'),
compile: function (str, path) {
return stylus(str)
@@ -152,6 +148,7 @@ passport.use(new LocalStrategy(
}
));
+// default routes
app.get('/login', function (req, res) {
var user = req.user, message = req.flash('error');
res.render('login', {
@@ -173,18 +170,10 @@ app.get('/logout', function (req, res) {
res.redirect('/');
});
-function ensureAuthenticated(req, res, next) {
- if (req.isAuthenticated()) {
- return next();
- }
- res.redirect('/login');
-}
-
// default routes
-app.get('/', routes.index);
-
-// app.get('/users', ensureAuthenticated, user.list);
+// routes
+require('./routes')(app, config);
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
@@ -6,13 +6,13 @@
/* TEAM */
Web Developer / Graphic Designer: Ariel Oscar Falduto
- Site: http://sandbox.outa.im
+ Site: http://nbp.outa.im
Twitter: @outa7iME
Contact: afalduto at gmail dot com
From: Buenos Aires, Argentina
/* SITE */
Last update: @@timestamp
Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
- Components: H5BP, Modernizr, jQuery, Twitter Bootstrap, LESS, Jade, Grunt
- Software: Sublime Text 2, Photoshop
+ Components: Express, Jade, Stylus, Mongoose, Passport, Grunt, H5BP, Modernizr, jQuery, Twitter Bootstrap
+ Software: Sublime Text 2
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -1,6 +1,6 @@
How To Create Fixtures
======================
-If you want to play with nbp use the following scripts to create the initial data:
+If you want to play with nbp use the following script to create the initial dummy data:
> node fixtures/populate.js
View
@@ -4,17 +4,25 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: '<json:package.json>',
lint: {
- app: ['grunt.js', 'app.js', 'models/**/*.js', 'routes/**/*.js', 'fixtures/**/*.js']
+ app: [
+ 'grunt.js',
+ 'app.js',
+ 'models/**/*.js',
+ 'routes/**/*.js',
+ 'helpers/**/*.js',
+ 'fixtures/**/*.js',
+ 'assets/javascripts/**/*.js'
+ ]
},
replace: {
- dist: {
+ app: {
options: {
variables: {
timestamp: '<%= grunt.template.today() %>'
}
},
files: {
- 'public/': ['build/humans.txt']
+ 'public/': ['assets/humans.txt']
}
}
},
View
@@ -0,0 +1,12 @@
+
+module.exports = {
+
+ /** Check user auth, if not redirs to login. **/
+ ensureAuthenticated: function (req, res, next) {
+ if (req.isAuthenticated()) {
+ return next();
+ }
+ res.redirect('/login');
+ }
+
+};
View
@@ -37,7 +37,6 @@ UserSchema.pre('save', function (next) {
if (!user.isModified('password')) {
return next();
}
-
// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, function (err, salt) {
if (err) {
View
@@ -6,7 +6,7 @@
/* TEAM */
Web Developer / Graphic Designer: Ariel Oscar Falduto
- Site: http://sandbox.outa.im
+ Site: http://nbp.outa.im
Twitter: @outa7iME
Contact: afalduto at gmail dot com
From: Buenos Aires, Argentina
View
@@ -0,0 +1,10 @@
+
+var Helper = require('../../helpers');
+
+module.exports = function (app, config) {
+
+ app.get('/restricted', Helper.ensureAuthenticated, function (req, res) {
+ res.render('index');
+ });
+
+};
View
@@ -1,8 +1,30 @@
-/*
- * GET home page.
- */
+var
+
+ // basic
+ fs = require('fs'),
+ Path = require('path');
+
+module.exports = function (app, config) {
+
+ app.get('/', function (req, res) {
+ res.render('index');
+ });
+
+ // custom
+ var dir = Path.join(__dirname, 'custom');
+ fs.readdirSync(dir).map(function (name) {
+ return Path.join(dir, name);
+ }).filter(function (path) {
+ return fs.statSync(path).isFile();
+ }).filter(function (path) {
+ return (/\.js$/).test(path);
+ }).forEach(function (path) {
+ require(path)(app, config);
+ if (config.verbose) {
+ // FIXME: Export to generic
+ console.log('\x1B[0;36mnbp:\x1B[0m route loaded: %s', path);
+ }
+ });
-exports.index = function (req, res) {
- res.render('index');
};
View
@@ -1,8 +0,0 @@
-
-/*
- * GET users listing.
- */
-
-exports.list = function (req, res) {
- res.send("respond with a resource");
-};

0 comments on commit 7799218

Please sign in to comment.