Skip to content

Commit 2b14309

Browse files
author
John Conrad Lumacad
authored
Merge pull request #45 from jcmlumacad/dev
enhanced mean stack
2 parents 03e4aea + 2a1a567 commit 2b14309

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
public/
44
node_modules/
55
bower_components/
6+
package-lock.json

Gruntfile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ module.exports = function(grunt) {
8989
copy: {
9090
main: {
9191
files: [
92-
{ expand: true, cwd: 'resources/assets/fonts', src: ['**'], dest: 'public/assets/fonts' },
93-
{ expand: true, cwd: 'bower_components/font-awesome/fonts', src: ['**'], dest: 'public/assets/fonts' },
94-
{ expand: true, cwd: 'bower_components/bootstrap/dist', src: ['**'], dest: 'public/assets/bootstrap' },
95-
{ expand: true, flatten: true, cwd: 'bower_components/', src: ['**/*.min.js', '**/*.min.js.map'], dest: 'public/assets/js', filter: 'isFile' }
92+
{ expand: true, cwd: 'resources/assets/fonts', src: ['**'], dest: 'public/assets/fonts' },
93+
{ expand: true, cwd: 'bower_components/font-awesome/fonts', src: ['**'], dest: 'public/assets/fonts' },
94+
{ expand: true, cwd: 'bower_components/bootstrap/dist', src: ['**'], dest: 'public/assets/bootstrap' }
9695
]
9796
}
9897
}
@@ -103,5 +102,6 @@ module.exports = function(grunt) {
103102
grunt.loadNpmTasks('grunt-contrib-watch');
104103
grunt.loadNpmTasks('grunt-contrib-sass');
105104
grunt.loadNpmTasks('grunt-contrib-copy');
106-
grunt.registerTask('default', ['browserify', 'uglify', 'sass', 'copy', 'watch']);
105+
grunt.registerTask('default', ['browserify', 'sass', 'copy', 'watch']);
106+
grunt.registerTask('prod', ['browserify', 'uglify', 'sass', 'copy', 'watch']);
107107
};

app.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
'use strict';
22

33
var express = require('express'),
4+
ENV = require('node-env-file')(__dirname + '/.env'), // Load .env in the root directory of the this project
45
app = express();
56

6-
// Load environment properties from a .env file for local development
7-
require('dotenv').load({ silent: true });
7+
// Get environment properties from a .env file for local development
8+
app.ENV = ENV;
9+
// Get port in .env or else use default port `3000`
10+
app.ENV.NODE_PORT = app.ENV.NODE_PORT || 3000;
811

9-
// Views
12+
// If the development is for testing purpose or development. Use 'local'
13+
if (app.ENV.NODE_DEVELOPMENT === 'local') {
14+
app.ENV.NODE_URL += ':' + app.ENV.NODE_PORT;
15+
}
16+
17+
// Gzip compression
18+
require('./config/lib/compress')(app);
19+
20+
// Libraries for client-side
21+
app.use('/bower_components', express.static(__dirname + '/bower_components'));
22+
// Assets
1023
app.use('/public', express.static(__dirname + '/public'));
24+
// HTML Files
1125
app.use('/views', express.static(__dirname + '/resources/views'));
1226

27+
// Helpers that can be use globally in the server
1328
require('./config/lib/helpers');
29+
// This library uses req.body for requests like POST method, etc.
1430
require('./config/lib/body-parser')(app);
31+
// This library uses for security purposes like session, crsf, passport, and helmet.
1532
require('./config/lib/middleware')(app);
33+
// Set csrf token in cookie
1634
require('./config/lib/csrf')(app);
35+
// Centralized error handler
1736
require('./config/lib/handler')(app);
37+
// Database configuration
1838
require('./config/lib/mongoose')(app);
39+
// Set of routes in an application
1940
require('./config/lib/routes')(app);
41+
// Passport configuration
2042
require('./config/lib/passport')(app);
2143

2244
module.exports = app;

config/lib/compress.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
var compression = require('compression');
4+
5+
module.exports = function (app) {
6+
/* GZIP Compression */
7+
app.use(compression({ filter: shouldCompress }));
8+
};
9+
10+
function shouldCompress(req, res) {
11+
if (req.headers['x-no-compression']) {
12+
return false;
13+
}
14+
15+
return compression.filter(req, res);
16+
}

config/lib/passport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = function (app) {
2323
}, function (email, password, done) {
2424
User.findOne({ email: email }, function (err, user) {
2525
if (err) { return done(err); }
26-
if ( ! user) { return done(null, false); }
27-
if ( ! user.verifyPassword(password)) { return done(null, false); }
26+
if (!user) { return done(null, false); }
27+
if (!user.verifyPassword(password)) { return done(null, false); }
2828
return done(null, user);
2929
});
3030
}));

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
],
1414
"dependencies": {
1515
"body-parser": "^1.15.2",
16+
"compression": "^1.6.2",
1617
"cookie-parser": "^1.4.3",
1718
"csurf": "^1.9.0",
18-
"dotenv": "^2.0.0",
1919
"express": "^4.14.0",
2020
"express-session": "^1.14.2",
2121
"helmet": "^3.1.0",
2222
"method-override": "^2.3.7",
2323
"mongoose": "^4.7.0",
24+
"mongoose-paginate": "^5.0.3",
25+
"node-env-file": "^0.1.8",
2426
"passport": "^0.3.2",
2527
"passport-local": "^1.0.0",
28+
"request": "^2.81.0",
2629
"socket.io": "^1.7.1",
2730
"tmj-passport": "^1.0.0"
2831
},

server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ io.on('connection', function(socket) {
99
// TODO: Socket
1010
});
1111

12-
server.listen(port);
13-
console.log('Node development server started on ' + process.env.NODE_URL + ':' + port + '/');
12+
server.listen(port, function () {
13+
console.log('Node development server started on ' + app.ENV.NODE_URL);
14+
});

0 commit comments

Comments
 (0)