-
-
Save arush/fab31f2c47a3c9f1210b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var express = require('express'), | |
path = require('path'), | |
config = require('./config/config'), | |
fs = require('fs') | |
//api = require('./api'); | |
var app = module.exports = express(); | |
// Configuration stuff | |
app.configure(function(){ | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
}); | |
var port; | |
// Force SSL | |
app.all('*',function(req,res,next){ | |
if (req.headers["x-forwarded-proto"] === "https") { | |
return next(); | |
} | |
res.redirect("https://" + req.headers.host + req.url); | |
}); | |
var api = require('./api'); | |
app.use('/api',api); | |
var serveStaticFiles = function(mode,app) { | |
if (mode == "development") { | |
app.use(function(req,res,next){ | |
if (req.host == "localhost") { | |
console.log("Redirecting to brandid.dev.com"); | |
res.redirect("http://brandid.dev.com:3000"+req.url); | |
} | |
else next() | |
}); | |
app.use(express.compress()); | |
app.use('/',express.static(config.MaleAppPath)); | |
port = 3000; | |
//app.use('/male',express.static(config.MaleAppPath)); | |
} else if (mode == "production") { | |
// Redirect to www.getbrandid.com | |
app.use(function(req,res,next){ | |
if (req.host == "getbrandid.com") { | |
res.redirect(301,"https://www.getbrandid.com"+req.url); | |
} | |
else next(); | |
}); | |
port = 3000; | |
var oneYear = 31557600000; | |
app.use(express.compress()); | |
app.use('/',express.static(config.MaleAppPath, {maxAge:oneYear})); | |
// app.use(express.static(config.MaleAppPath,{maxAge:oneYear})); | |
//app.use('/male',express.static(config.MaleAppPath),{maxAge:oneYear}); | |
} | |
} | |
app.configure('development', function(){ | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
serveStaticFiles('development',app); | |
}); | |
app.configure('production', function(){ | |
app.use(express.errorHandler()); | |
serveStaticFiles('production',app); | |
}); | |
// Mount api! | |
//app.use('/api',api); | |
// Start server | |
app.listen(port, function(){ | |
console.log("Express Brandid Assbreaking server listening on port %d in %s mode", this.address().port, app.settings.env); | |
}); | |
process.on('uncaughtException', function (exception) { | |
console.log('Uncaught exception'); | |
console.log(exception); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment