Using coffee instead (derby new --coffee first-project)

This commit is contained in:
Tyler Renelle
2012-04-26 22:19:31 -04:00
parent 2f8b80b74e
commit 45caad3c3c
9 changed files with 142 additions and 158 deletions
+51
View File
@@ -0,0 +1,51 @@
http = require 'http'
path = require 'path'
express = require 'express'
gzippo = require 'gzippo'
derby = require 'derby'
app = require '../app'
serverError = require './serverError'
## SERVER CONFIGURATION ##
ONE_YEAR = 1000 * 60 * 60 * 24 * 365
root = path.dirname path.dirname __dirname
publicPath = path.join root, 'public'
(expressApp = express())
.use(express.favicon())
# Gzip static files and serve from memory
.use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
# Gzip dynamically rendered content
.use(express.compress())
# Uncomment to add form data parsing support
# .use(express.bodyParser())
# .use(express.methodOverride())
# Derby session middleware creates req.model and subscribes to _session
# .use(express.cookieParser 'secret_sauce')
# .use(express.session
# cookie: {maxAge: ONE_YEAR}
# )
# .use(app.session())
# The router method creates an express middleware from the app's routes
.use(app.router())
.use(expressApp.router)
.use(serverError root)
module.exports = server = http.createServer expressApp
## SERVER ONLY ROUTES ##
expressApp.all '*', (req) ->
throw "404: #{req.url}"
## STORE SETUP ##
store = app.createStore listen: server
+18
View File
@@ -0,0 +1,18 @@
derby = require 'derby'
{isProduction} = derby.util
module.exports = (root) ->
staticPages = derby.createStatic root
return (err, req, res, next) ->
return next() unless err?
console.log(if err.stack then err.stack else err)
## Customize error handling here ##
message = err.message || err.toString()
status = parseInt message
if status is 404
staticPages.render '404', res, {url: req.url}, 404
else
res.send if 400 <= status < 600 then status else 500