Skip to content

Commit

Permalink
(add) router/config documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Apr 13, 2015
1 parent d4949d5 commit 838fb6a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 55 deletions.
36 changes: 0 additions & 36 deletions npm-debug.log

This file was deleted.

14 changes: 9 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -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);
});
40 changes: 29 additions & 11 deletions server/config.js
Original file line number Diff line number Diff line change
@@ -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('/');
});
22 changes: 19 additions & 3 deletions server/router.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand All @@ -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);
};

0 comments on commit 838fb6a

Please sign in to comment.