Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Started edge branch that uses latest versions of everything

  • Loading branch information...
commit 63203b69e57b54671fa944a0ef172b0d0bd0e098 1 parent 68dda10
Hunter Loftis authored
39 app/config/constants.js
... ... @@ -0,0 +1,39 @@
  1 +exports = module.exports = function() {
  2 +
  3 + // Options
  4 +
  5 + var TWO_WEEKS = 14 * 24 * 60 * 60 * 1000;
  6 +
  7 + var option_tables = {
  8 + development: function() {
  9 + this.maxAge = 14 * 24 * 60 * 60 * 1000 // Two weeks // Time before a session goes stale
  10 + this.shortSession = 12 * 24 * 60 * 60 * 1000 // We no longer have a short session option 1000 * 60 * 60 * 60 // 60 minutes
  11 + this.reqTimeout = 30000
  12 + this.sessionKey = 'session'
  13 + this.host = 'http://localhost:3100'
  14 + this.port = 3100
  15 + this.dumpExceptions = true
  16 + this.showStack = true
  17 + this.errorToHtml = true
  18 + //this.redis = { host: 'localhost', port: 6379, db: 'clickdummy' }
  19 + //this.mongo = { db: 'mongodb://localhost/passport'}
  20 + //this.mysql = { host: 'localhost', port: 3306, user: 'root', password: 'root', database: 'clickdummy' }
  21 + },
  22 + staging: function() {
  23 + this.host = 'http://clickdummy.skookumlabs.com'
  24 + this.dumpExceptions = false
  25 + this.errorToHtml = false
  26 + },
  27 + production: function() {
  28 + this.host = "http://clickdummy.com"
  29 + }
  30 + }
  31 +
  32 + // Cascade options
  33 +
  34 + option_tables.staging.prototype = new option_tables.development()
  35 + option_tables.production.prototype = new option_tables.staging()
  36 +
  37 + return option_tables;
  38 +
  39 +}
26 app/config/errors.js
... ... @@ -0,0 +1,26 @@
  1 +exports = module.exports = function(server) {
  2 +
  3 + // Handle uncaught exceptions
  4 +
  5 + process.on("uncaughtException", function(err){
  6 + console.warn("caught unhandled exception:")
  7 + console.warn(err.stack || err)
  8 + console.log("Exiting process due to uncaught exception!")
  9 + process.exit()
  10 + })
  11 +
  12 +
  13 + // Respond to standard request errors
  14 +
  15 + server.error(function(err, req, res, next){
  16 + if (!err || 2 !== err.errno)
  17 + return res.render("500.jade", { layout: "layout.error.jade" }, function(err, content){
  18 + res.send(content || "Internal Server Error", 500)
  19 + })
  20 +
  21 + res.render("404.jade", { layout: "layout.error.jade" }, function(err, content){
  22 + res.send(content || "File Not Found", 404)
  23 + })
  24 + })
  25 +
  26 +}
4 app/config/routes.js
... ... @@ -1,7 +1,7 @@
1   -var home = require('controllers/home')
  1 +var home = require('controllers/home');
2 2
3 3 exports = module.exports = function(server) {
4 4
5   - server.map('all', '/', home.index)
  5 + server.all('/', home.index);
6 6
7 7 }
74 app/config/server.js
... ... @@ -1,4 +1,3 @@
1   -
2 1 // Application root - where to start building require() paths
3 2
4 3 var root = __dirname + '/../..'
@@ -12,44 +11,21 @@ require.paths.unshift(
12 11
13 12 // Modules
14 13
15   -var express = require('express')
16   -
17   -require('math.uuid')
  14 +var express = require('express'),
  15 + connectTimeout = require('connect-timeout');
18 16
19   -// Options
  17 +require('math.uuid');
20 18
21   -var TWO_WEEKS = 14 * 24 * 60 * 60 * 1000
  19 +// Constants
22 20
23   -var option_tables = {
24   - development: {
25   - forceCompile: true,
26   - reapInterval: TWO_WEEKS,
27   - maxAge: TWO_WEEKS,
28   - reqTimeout: 10000,
29   - sessionKey: 'devsession'
30   - },
31   - staging: {
32   - forceCompile: false,
33   - reapInterval: TWO_WEEKS,
34   - maxAge: TWO_WEEKS,
35   - reqTimeout: 10000,
36   - sessionKey: 'stagingsession'
37   - },
38   - production: {
39   - forceCompile: false,
40   - reapInterval: TWO_WEEKS,
41   - maxAge: TWO_WEEKS,
42   - reqTimeout: 10000,
43   - sessionKey: 'prodsession'
44   - }
45   -}
  21 +var constants = require('constants')();
46 22
47 23 // Server export
48 24
49 25 exports = module.exports = function() {
50 26
51 27 var server = express.createServer(),
52   - options = option_tables[server.set('env')]
  28 + options = constants[server.set('env')];
53 29
54 30 // Config (all)
55 31
@@ -60,12 +36,14 @@ exports = module.exports = function() {
60 36 server.set('app root', root + '/app')
61 37 server.set('view engine', options.view_engine || 'jade')
62 38 server.set('views', server.set('app root') + '/views')
  39 + server.set('port', options.port);
  40 + server.set('host', options.host);
63 41
64 42 // Middleware
65 43
66   - //server.use(connectTimeout({ time: options.reqTimeout }))
  44 + server.use(connectTimeout({ time: options.reqTimeout }))
67 45 server.use(express.conditionalGet())
68   - server.use(express.compiler({ src: server.set('app root') + '/public', enable: ['less'], forceCompile: options.forceCompile || false }))
  46 + server.use(express.compiler({ src: server.set('app root') + '/public' }));
69 47 server.use(express.staticProvider(server.set('app root') + '/public'))
70 48 server.use(express.cookieDecoder())
71 49 server.use(express.session({
@@ -78,14 +56,11 @@ exports = module.exports = function() {
78 56 }))
79 57 server.use(express.bodyDecoder())
80 58 server.use(server.router)
  59 + server.use(express.errorHandler({ dumpExceptions: options.dumpExceptions, showStack: options.showStack}))
81 60
82 61 // Helpers
83 62
84 63 require('./helpers')(server)
85   -
86   - // Resourceful routing
87   -
88   - require('resourceful')(server)
89 64
90 65 // Map routes
91 66
@@ -96,19 +71,14 @@ exports = module.exports = function() {
96 71 // Config (development)
97 72
98 73 server.configure('development', function() {
99   - server.use(express.errorHandler({ dumpExceptions: true, showStack: true}))
100 74 server.use(express.logger({ format: ':method :url :status' }));
101   - server.set('port', 100)
102   - server.set('host', 'http://localhost:100')
  75 +
103 76 })
104 77
105 78 // Config (staging)
106 79
107 80 server.configure('staging', function() {
108   - server.use(express.errorHandler({ dumpExceptions: true, showStack: false}))
109 81 server.use(express.logger({ format: ':method :url :status' }));
110   - server.set('port', 100)
111   - server.set('host', 'http://staging.maximum.com')
112 82 })
113 83
114 84 // Config (production)
@@ -117,25 +87,9 @@ exports = module.exports = function() {
117 87
118 88 })
119 89
120   - // Handle uncaught exceptions (no crashing)
121   -
122   - process.on("uncaughtException", function(err){
123   - console.warn("caught unhandled exception:")
124   - console.warn(err.stack || err)
125   - })
126   -
127   - // Respond to standard request errors
  90 + // Handle errors
128 91
129   - server.error(function(err, req, res, next){
130   - if (!err || 2 !== err.errno)
131   - return res.render("500.jade", { layout: "layout.error.jade" }, function(err, content){
132   - res.send(content || "Internal Server Error", 500)
133   - })
  92 + require('./errors.js')(server)
134 93
135   - res.render("404.jade", { layout: "layout.error.jade" }, function(err, content){
136   - res.send(content || "File Not Found", 404)
137   - })
138   - })
139   -
140 94 return server // Export the server
141 95 }
7 package.json
@@ -2,9 +2,10 @@
2 2 "name":"newproject",
3 3 "version":"0.0.1",
4 4 "dependencies":{
5   - "jade":"https://github.com/Skookum/jade/tarball/master",
6   - "express":"https://github.com/Skookum/express/tarball/master",
7   - "resourceful":"https://github.com/Skookum/resourceful/tarball/master"
  5 + "jade":">=0.9.2",
  6 + "express":">=2.0.0",
  7 + "stylus":">=0.9.2",
  8 + "connect-timeout":">=0.0.1"
8 9 },
9 10 "directories":{}
10 11 }

0 comments on commit 63203b6

Please sign in to comment.
Something went wrong with that request. Please try again.