Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (32 sloc) 0.956 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
http = require 'http'
path = require 'path'
express = require 'express'
gzippo = require 'gzippo'
derby = require 'derby'
todos = require '../todos'
serverError = require './serverError'

## SERVER CONFIGURATION ##

expressApp = express()
server = http.createServer expressApp
module.exports = server

store = derby.createStore
listen: server
require('./queries')(store)

ONE_YEAR = 1000 * 60 * 60 * 24 * 365
root = path.dirname path.dirname __dirname
publicPath = path.join root, 'public'

expressApp
.use(express.favicon())
# Gzip static files and serve from memory
.use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
# Gzip dynamically rendered content
.use(express.compress())

# Adds req.getModel method
.use(store.modelMiddleware())
# Creates an express middleware from the app's routes
.use(todos.router())
.use(expressApp.router)
.use(serverError root)


## SERVER ONLY ROUTES ##

expressApp.all '*', (req) ->
throw "404: #{req.url}"
Something went wrong with that request. Please try again.