2012년 7월 16일 월요일

coffeescript로 만들어보는 html(jade/ejs 아님)사용 boilerplate


express = require 'express'
gzippo = require 'gzippo'
app = express.createServer express.logger()
store = new express.session.MemoryStore
api = require './api/apis'

tmpl =
compile: (source, options)->
    (locals)->
      source

app.configure ()->
  app.set 'views', "#{__dirname}/public"
  app.use express.cookieParser()
  app.use express.session secret: '<sessionkey>', store: store
  app.use gzippo.staticGzip "#{__dirname}/public"
  app.set 'view options', layout: false
  app.set 'view engine', 'html'
  app.register '.html',
    tmpl

# APIs
app.post '/api/auth/login', api.login
app.get '/api/auth/logout', api.logout

app.get '*', (request, response) ->
  response.render "index.html"
port = process.env.PORT || 3000
app.listen port, ()->
    console.log "Listening on " + port