Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
Add inline code docs for server.js. Refs #46
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Das Modak <[email protected]>
  • Loading branch information
Kaustav Das Modak committed Apr 27, 2015
1 parent 6a21cd6 commit e85756c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/usr/bin/env node

/**
* Grouphone Web client server main script
*
* This script starts the Grouphone Web client server by loading in all the required dependencies. This is the first
* point of entry for the application.
*
* Here are the thing it does:
*
* - require-s all the dependencies
* - Prepares an `expressjs` `app` instance
* - Sets globals that can be accessed throughout the application.
* - Sets up authentication middlewares
* - Configures the ExpressJS server instance
* - Mounts the `./static` directory as a static file server on the web root
* - Mounts the `./libs/routes` module
* - Sets up a https server using security configurations specified in `config.js`
*/

// Require dependencies
var express = require("express"),
https = require("https"),
fs = require("fs"),
Expand All @@ -8,14 +27,15 @@ var express = require("express"),
cookieParser = require("cookie-parser"),
config = require("./config");

// Instantiate express app
var app = express();

// Override port from third commandline argument, if present
if (process.argv && process.argv[2]) {
config.APP_PORT = parseInt(process.argv[2]);
}

// Set useful globals
// Set useful globals. These globals are accessible as `config`, `approot` and `utils` from the routes and views.
global.config = config,
global.approot = __dirname + "/";
global.utils = require("./libs/utils");
Expand All @@ -26,10 +46,15 @@ app.use(function (req, res, next) {
next();
});

// Configure application
// -- Configure application --
// Set view engine to ejs
app.set("view engine", "ejs");

// Enable body-parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Enable cookie-parser with the salt specified in the config
app.use(cookieParser(config.SALT));

// Middleware to populate `req.user` with user information.
Expand All @@ -48,9 +73,9 @@ app.use(function (req, res, next) {
next();
});

// Register routes
app.use("/", express.static(path.join(__dirname, "static")));
app.use("/", require("./libs/routes"));
// -- Register routes --
app.use("/", express.static(path.join(__dirname, "static"))); // Mounts the ./static directory on root
app.use("/", require("./libs/routes")); // Mounts the routes

// Set https options
var https_options = {
Expand Down

0 comments on commit e85756c

Please sign in to comment.