windhamdavid 3 years ago
parent
commit
d66ce6c8c8
5 changed files with 103 additions and 32 deletions
  1. 1 0
      .gitignore
  2. 41 23
      app.js
  3. 5 8
      controllers/user.js
  4. 2 1
      package.json
  5. 54 0
      routes/routes.js

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 .DS_Store
+log/*
 *.log
 npm-debug.log*
 node_modules

+ 41 - 23
app.js

@@ -11,6 +11,8 @@ var errorHandler = require('errorhandler');
 var events = require('events');
 var http = require('http');
 var path = require('path');
+var FileStreamRotator = require('file-stream-rotator')
+var fs = require('fs')
 var logger = require('morgan');
 
 var _ = require('lodash');
@@ -22,6 +24,7 @@ var lusca = require('lusca');
 var expressValidator = require('express-validator');
 
 
+
 /********** Config **************/
 
 var app = express();
@@ -34,6 +37,7 @@ var secure = require('./config/secure');
 var passportConf = require('./config/passport');
 
 
+
 /********** MongoDB **************/
 
 mongoose.connect(secure.db);
@@ -57,6 +61,7 @@ app.set('views', path.join(__dirname, 'app/views'));
 
 
 
+
 /********** app.use **************/
 
 app.use(express.static(path.join(__dirname, 'app'), { maxAge: 31557600000 }));
@@ -95,37 +100,41 @@ app.use(function(req, res, next) {
 
 /********** routes controllers **************/
 
-require('./routes/routes')(app);
+var router = express.Router();
+app.use(router);
+require('./routes/routes');
 
 var homeController = require('./controllers/home');
+var staticController = require('./controllers/static');
 var userController = require('./controllers/user');
 var contactController = require('./controllers/contact');
 var apiController = require('./controllers/api');
 
-app.get('/', homeController.index);
-app.get('/login', userController.getLogin);
-app.post('/login', userController.postLogin);
-app.get('/logout', userController.logout);
-app.get('/forgot', userController.getForgot);
-app.post('/forgot', userController.postForgot);
-app.get('/reset/:token', userController.getReset);
-app.post('/reset/:token', userController.postReset);
-app.get('/register', userController.getSignup);
-app.post('/register', userController.postSignup);
-app.get('/contact', contactController.getContact);
-app.post('/contact', contactController.postContact);
-app.get('/account', passportConf.isAuthenticated, userController.getAccount);
-app.post('/account/profile', passportConf.isAuthenticated, userController.postUpdateProfile);
-app.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
-app.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
-app.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
+
+router.get('/', homeController.index);
+router.get('/terms', staticController.static);
+
+router.get('/login', userController.getLogin);
+router.post('/login', userController.postLogin);
+router.get('/logout', userController.logout);
+router.get('/forgot', userController.getForgot);
+router.post('/forgot', userController.postForgot);
+router.get('/reset/:token', userController.getReset);
+router.post('/reset/:token', userController.postReset);
+router.get('/register', userController.getSignup);
+router.post('/register', userController.postSignup);
+router.get('/contact', contactController.getContact);
+router.post('/contact', contactController.postContact);
+router.get('/account', passportConf.isAuthenticated, userController.getAccount);
+router.post('/account/profile', passportConf.isAuthenticated, userController.postUpdateProfile);
+router.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
+router.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
+router.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
 
 
 /********** static routes controllers **************/
 
-var staticController = require('./controllers/static');
 
-app.get('/terms', staticController.static);
 app.get('/privacy', function(req, res) {
   res.render('pages/privacy', {
     title: 'Privacy Policy'
@@ -133,12 +142,16 @@ app.get('/privacy', function(req, res) {
 });
 
 
-/********** oauth routes controllers **************/
 
 
+/************* log **************/
 
 
-/************* log **************/
+app.use(logger('common', {
+    stream: fs.createWriteStream('./log/access.log', {flags: 'a'})
+}));
+app.use(logger('dev'));
+
 
 var logger = new events.EventEmitter();
 logger.on('newEvent', function(event, data) {
@@ -146,9 +159,14 @@ logger.on('newEvent', function(event, data) {
 });
 
 
+
 /************* errors **************/
 
-app.use(errorHandler());
+
+if (process.env.NODE_ENV === 'development') {
+  app.use(errorHandler())
+};
+
 
 
 /********** app.listen **************/

+ 5 - 8
controllers/user.js

@@ -110,20 +110,17 @@ exports.postSignup = function(req, res, next) {
 };
 
 
-/**
- * GET /account
- * Profile page.
- */
+/********** GET / Account **************/
+
 exports.getAccount = function(req, res) {
   res.render('account/profile', {
     title: 'Account Management'
   });
 };
 
-/**
- * POST /account/profile
- * Update profile information.
- */
+
+/********** POST / Account **************/
+
 exports.postUpdateProfile = function(req, res, next) {
   User.findById(req.user.id, function(err, user) {
     if (err) {

+ 2 - 1
package.json

@@ -19,13 +19,14 @@
     "body-parser": "^1.14.1",
     "connect-mongo": "^0.8.2",
     "cookie-parser": "^1.3.5",
-    "debug": "~2.2.0",
     "errorhandler": "^1.4.2",
     "express": "^4.13.3",
     "express-flash": "0.0.2",
     "express-handlebars": "^2.0.1",
     "express-session": "^1.12.1",
     "express-validator": "^2.18.0",
+    "file-stream-rotator": "0.0.6",
+    "fs": "0.0.2",
     "lodash": "^3.10.1",
     "lusca": "^1.3.0",
     "method-override": "^2.3.5",

+ 54 - 0
routes/routes.js

@@ -0,0 +1,54 @@
+var express = require('express');
+var app = express();
+var router = express.Router();
+var path = require('path');
+var secure = require('../config/secure');
+var passportConf = require('../config/passport');
+
+app.use(express.static(path.join(__dirname, './app'), { maxAge: 31557600000 }));
+
+
+/********** routes controllers **************/
+
+var homeController = require('../controllers/home');
+var staticController = require('../controllers/static');
+var userController = require('../controllers/user');
+var contactController = require('../controllers/contact');
+var apiController = require('../controllers/api');
+
+
+router.get('/', homeController.index);
+router.get('/terms', staticController.static);
+
+router.get('/login', userController.getLogin);
+router.post('/login', userController.postLogin);
+router.get('/logout', userController.logout);
+router.get('/forgot', userController.getForgot);
+router.post('/forgot', userController.postForgot);
+router.get('/reset/:token', userController.getReset);
+router.post('/reset/:token', userController.postReset);
+router.get('/register', userController.getSignup);
+router.post('/register', userController.postSignup);
+router.get('/contact', contactController.getContact);
+router.post('/contact', contactController.postContact);
+router.get('/account', passportConf.isAuthenticated, userController.getAccount);
+router.post('/account/profile', passportConf.isAuthenticated, userController.postUpdateProfile);
+router.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
+router.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
+router.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
+
+
+/********** static routes controllers **************/
+
+
+app.get('/privacy', function(req, res) {
+  res.render('pages/privacy', {
+    title: 'Privacy Policy'
+  });
+});
+
+
+/********** oauth routes controllers **************/
+
+
+module.exports = router