From 838fb6ae95f80175e1174c4f11b7a6104fb709bd Mon Sep 17 00:00:00 2001 From: garrettjoecox Date: Mon, 13 Apr 2015 00:59:41 -0700 Subject: [PATCH] (add) router/config documentation --- npm-debug.log | 36 ------------------------------------ server.js | 14 +++++++++----- server/config.js | 40 +++++++++++++++++++++++++++++----------- server/router.js | 22 +++++++++++++++++++--- 4 files changed, 57 insertions(+), 55 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index c75912a..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,36 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ] -2 info using npm@2.5.1 -3 info using node@v0.12.0 -4 verbose node symlink /usr/local/bin/node -5 verbose run-script [ 'prestart', 'start', 'poststart' ] -6 info prestart populr@1.0.0 -7 info start populr@1.0.0 -8 verbose unsafe-perm in lifecycle true -9 info populr@1.0.0 Failed to exec start script -10 verbose stack Error: populr@1.0.0 start: `node server.js` -10 verbose stack Exit status 1 -10 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16) -10 verbose stack at EventEmitter.emit (events.js:110:17) -10 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:14:12) -10 verbose stack at ChildProcess.emit (events.js:110:17) -10 verbose stack at maybeClose (child_process.js:1008:16) -10 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1080:5) -11 verbose pkgid populr@1.0.0 -12 verbose cwd /Users/markmarcantano/git/populr -13 error Darwin 14.3.0 -14 error argv "node" "/usr/local/bin/npm" "start" -15 error node v0.12.0 -16 error npm v2.5.1 -17 error code ELIFECYCLE -18 error populr@1.0.0 start: `node server.js` -18 error Exit status 1 -19 error Failed at the populr@1.0.0 start script 'node server.js'. -19 error This is most likely a problem with the populr package, -19 error not with npm itself. -19 error Tell the author that this fails on your system: -19 error node server.js -19 error You can get their info via: -19 error npm owner ls populr -19 error There is likely additional logging output above. -20 verbose exit [ 1, true ] diff --git a/server.js b/server.js index 88086dd..77fee1e 100644 --- a/server.js +++ b/server.js @@ -1,10 +1,14 @@ -// Imports the server configuration -var app = require('./server/config'); -// Sets port to deployed port or local 9000 +/**************** + Server Engine +****************/ + +/* + Runs the configuration and starts up the server +*/ +var app = require('./server/config'); var port = process.env.PORT || 9000; -// Starts server on provided port app.listen(port, function() { - console.log('listening on 9000'); + console.log('listening on', port); }); diff --git a/server/config.js b/server/config.js index 470b5b5..e0e4fee 100644 --- a/server/config.js +++ b/server/config.js @@ -1,37 +1,55 @@ -/* Imports */ + +/**************** + Server Config +****************/ + +/* + Sets up the routing for the server, sending each + API request to its associated controller +*/ + +/* * Imports * */ + var express = require('express'); var bodyParser = require('body-parser'); var morgan = require('morgan'); -/* Declarations */ -module.exports = app = express(); -var topRouter = express.Router(); -var peopleRouter = express.Router(); -var twitterRouter = express.Router(); -var contextRouter = express.Router(); -var sitesRouter = express.Router(); +/* * Middleware * */ -/* Configuration */ +module.exports = app = express(); app.use(bodyParser.json()); -// app.use(morgan('dev')); app.use(express.static(__dirname + '/../client/dist/public')); +/* * API Routing * */ + +var topRouter = express.Router(); app.use('/api/top', topRouter); require('./router.js').top(topRouter); +var peopleRouter = express.Router(); app.use('/api/people', peopleRouter); require('./router.js').people(peopleRouter); +var twitterRouter = express.Router(); app.use('/api/twitter', twitterRouter); require('./router.js').twitter(twitterRouter); +var contextRouter = express.Router(); app.use('/api/context', contextRouter); require('./router.js').context(contextRouter); +var sitesRouter = express.Router(); app.use('/api/sites', sitesRouter); require('./router.js').sites(sitesRouter); -/* serves index on default */ +var facebookRouter = express.Router(); +app.use('/api/facebook', facebookRouter); +require('./router.js').facebook(facebookRouter); + +/* + Serves index on default + TODO: Fix this +*/ app.use(function(req, res) { res.redirect('/'); }); diff --git a/server/router.js b/server/router.js index 4bce58b..a484a50 100644 --- a/server/router.js +++ b/server/router.js @@ -1,12 +1,24 @@ -// Declaring the controllers +/**************** + Server Router +****************/ + +/* + Sets up the routing for the server, sending each + API request to its associated controller +*/ + +/* * Imports * */ + var topController = require('./database/top/controller'); var peopleController = require('./database/people/controller'); var twitterController = require('./database/twitter/controller'); var contextController = require('./database/context/controller'); var sitesController = require('./database/sites/controller'); +var facebookController = require('./database/facebook/controller'); + +/* * API route directing * */ -// Directing the given routes to the correct controllers module.exports.top = function(app) { app.param('id', topController.attachParam); app.get('/:id', topController.get); @@ -19,7 +31,6 @@ module.exports.people = function(app) { app.post('/', peopleController.post); }; -// Here for maybe future implementation? module.exports.twitter = function(app) { app.param('id', twitterController.attachParam); app.get('/:id', twitterController.get); @@ -34,3 +45,8 @@ module.exports.sites = function(app) { app.param('id', sitesController.attachParam); app.get('/:id', sitesController.get); }; + +module.exports.facebook = function(app) { + app.param('id', facebookController.attachParam); + app.get('/:id', facebookController.get); +};