Skip to content

Instantly share code, notes, and snippets.

@clayperez
Created February 25, 2016 16:45
Show Gist options
  • Save clayperez/320460091b80e26c652c to your computer and use it in GitHub Desktop.
Save clayperez/320460091b80e26c652c to your computer and use it in GitHub Desktop.
'use strict';
///////////////////
// app.rhesus.io //
///////////////////
///
///
///
require('./config.js');
/////////////////
// ENVIRONMENT //
/////////////////
///
///
///
/// CONSTANTS
const PORT = process.env.PORT || 8080; //the server port
/// OTHER ENVIRONMENTS
require('moment-duration-format');
//////////
// VARS //
//////////
///
///
///
/// USED LATER
var exec;
/// REQUIRES
var child_process = require('child_process');
var path = require('path');
var fs = require('fs');
var moment = require('moment');
var numeral = require('numeral');
var async = require('async');
var express = require('express');
var stormpath = require('express-stormpath');
var stripe = require('stripe')( process.env.STRIPE_APIKEY );
var bodyParser = require('body-parser');
var sassMiddleware = require('node-sass-middleware');
var Datastore = require('nedb');
/////////////////////
// INITIALIZATIONS //
/////////////////////
///
///
///
var app = express();
app.locals.moment = moment;
app.locals.numeral = numeral;
///
///
///
/// Your own super cool function
var logger = function(req, res, next) {
console.info("(REQ)", req.originalUrl, req.method, req.query);
next(); // Passing the request to the next handler in the stack.
}
app.use(logger); // Here you add your logger to the stack.
////////////////////////
// EXPRESS MIDDLEWARE //
////////////////////////
///
///
///
/// STORMPATH -- If not placed at top, your website will time out.
app.use(stormpath.init(app, {
website: true,
expand: {
customData: true
},
web: {
login: {
nextUri: '/dashboard'
}
},
postRegistrationHandler: function(account, req, res, next) {
req.user.customData.stripe = {};
req.user.customData.rhesus = {};
req.user.customData.save(function (err) {
if (err) { console.error('customData not saved', err); }
next();
});
}
}));
/// Parse URL encoded variables into req.body
app.use(bodyParser.urlencoded({ extended: true }));
/// Parse JSON data into req.body
app.use(bodyParser.json());
/// Render SCSS into CSS on the fly
app.use(sassMiddleware({
src: path.join(__dirname, 'www'),
debug: false,
outputStyle: 'compressed',
prefix: '/prefix'
}));
//////////////////
// REST ROUTING //
//////////////////
/// Ref: https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4
/// API Routing will be a future, advanced feature for developers writing plugins.
/// For basic account authorization and results posting, we only need to use
/// the existing user account customData.
///
/// var apiRouter = express.Router();
/// require('./API-routes.js')(apiRouter,app,stormpath);
var mothershipRouter = express.Router();
require('./mothership-routes.js')(mothershipRouter,app);
////////////////
// WWW ROUTES //
////////////////
///
///
///
/// Specify the view engine to EJS
/// http://ejs.co/
app.use(express.static('www'));
app.set('view engine', 'ejs');
app.set('views', './www/views');
/// ROUTES
require('./public-routes.js')(app);
require('./dashboard-routes.js')(app,stormpath);
require('./payment-routes.js')(app,stripe,stormpath);
require('./404-route.js')(app);
///////////////////////////////////////
// Launch Stormpath Protected Server //
///////////////////////////////////////
///
app.on('stormpath.ready', function () {
app.listen(PORT, function () {
console.log('Rhesus is running, fools. Better catch it.');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment