_ref = [JSON, Math, decodeURIComponent, encodeURIComponent, ((p) -> p.replace(/\/*$/, "").replace /^\/?/, "/" ), ((d, s) -> k = undefined v = undefined for k of s v = s[k] d[k] = ((if d[k] instanceof Array then d[k].concat(v) else v)) d ), (s, c) -> s.split(/\s+/).map c ] J = _ref[0] M = _ref[1] duc = _ref[2] euc = _ref[3] n = _ref[4] e = _ref[5] w = _ref[6] _ref1 = w("http url querystring fs async faye-websocket vault/node/aes haml ejs mime", require) http = _ref1[0] url = _ref1[1] qs = _ref1[2] fs = _ref1[3] async = _ref1[4] WS = _ref1[5] E = _ref1[6] haml = _ref1[7] ejs = _ref1[8] mime = _ref1[9] A = (-> A = (request, response, _m) -> c = undefined h = undefined _ref2 = undefined _this = this @request = request @response = response @_m = _m _ref2 = [{}, (@request.headers.cookie or "").split(/\s*;\s*/)] h = _ref2[0] c = _ref2[1] c.map (p) -> q = undefined q = p.split("=") h[duc(q[0])] = duc(q[1]) A.aes().decrypt h.session or "", (x, j) -> d = undefined i = undefined k = undefined v = undefined delete h.session _this.params = splat: [] _this.cookies = h _this.session = ((if x then {} else J.parse(j))) _this._u = url.parse(_this.request.url, true) _this._h = "Set-Cookie": [] e _this, A.h _this._b = A.r.filter((r) -> r[0] is _this._m and r[2].test(_this._u.pathname) )[0] _this._c (-> _i = undefined _len = undefined _ref3 = undefined _ref4 = undefined if @_b _ref3 = [[], @_u.pathname.match(@_b[2])] @_a = _ref3[0] d = _ref3[1] _ref4 = @_b[1] i = _i = 0 _len = _ref4.length while _i < _len k = _ref4[i] v = duc(d[i + 1]) @_a.push v if k is "*" @params.splat.push v else @params[k] = v i = ++_i e @params, ((if /\bapplication\/x-www-form-urlencoded\b/.test(@request.headers["content-type"]) then qs.parse(@request.body) else @_u.query)) ).call(_this) A::_x = (c) -> _this = this @_c = -> p = undefined p = _this._u.pathname if p.split("/").indexOf("..") >= 0 _this.response.writeHead 400, {} _this.response.end() else async.series A.b.filter((f) -> p.substr(0, f.c.length) is f.c ).map((f) -> -> f.apply _this, arguments_ ).concat(-> if _this._b c.call _this, (-> _this._b[3].apply _this, _this._a ) else fs.readFile (A["public"] or "./public") + p, (x, f) -> if x _this.response.writeHead 404, {} _this.response.end() else _this.response.writeHead 200, "Content-Length": f.length "Content-Type": mime.lookup(p) + "; charset=utf-8" _this.response.end f ) A::render = (s) -> _this = this s = ((if s is undefined then "" else String(s))) A.aes().encrypt J.stringify(@session), (x, j) -> h = undefined h = {} if s e h, "Set-Cookie": ["session=" + euc(j) + "; Path=/; HttpOnly"] "Content-Type": "text/html; charset=utf-8" "Content-Length": new Buffer(s, "utf8").length e h, _this._h _this.response.writeHead _this._s or 200, h _this.response.end s A::cookie = (c) -> k = undefined s = undefined v = undefined _results = undefined _results = [] for k of c v = c[k] _results.push v = (if typeof v is "string" then value: v else (v s = euc(k) + "=" + euc(v.value) + "; Path=" + v.path or "/" (if v.domain then s += "; Domain=" + v.domain else undefined) (if v.expires then s += "; Expires=" + v.expires.toGMTString() else undefined) (if v.http then s += "; HttpOnly" else undefined) (if v.secure then s += "; Secure" else undefined) e(@_h, "Set-Cookie": s ) )) _results A )() e A::, headers: ((o) -> e @_h, o ) status: ((n) -> @_s = parseInt(n, 10) ) redirect: ((u, s) -> s = 303 unless s? @status s @headers Location: u @render() ) haml: ((n) -> _this = this A.v "haml", n, (x, t) -> _this.render haml(t)(_this) ) ejs: ((n, o) -> _this = this A.v "ejs", n, (x, t) -> _this.render ejs.render(t, e(((if o? then o.locals else undefined)) or {}, A.h)) ) puts: (s) -> console.log s e A, r: [] c: [""] context: ((p, f) -> @c.push n(p) f this @c.pop() ) b: [] before: ((b) -> b.c = @c.join("") @b.push b ) h: {} helpers: ((o) -> e @h, o ) t: {} template: ((n, t) -> @t[n] = t ) v: ((t, n, c) -> f = undefined if f = @t[n + "." + t] c null, f else fs.readFile (@views or "./views") + "/" + n + "." + t, (x, f) -> c null, f.toString() ) run: ((q) -> http.createServer(@call).on("upgrade", @ws).listen q or 4567 ) aes: -> new E(@session_secret) w "get post put delete patch head options websocket eventsource", (v) -> A[v] = (p, f) -> m = undefined o = undefined p = n(@c.join("") + n(p)) o = (p.match(/[\/\.](\*|:[a-z\_\$][a-z0-9\_\$]*)/g) or []).map((s) -> s.replace /^[^a-z0-9\_\$\*]*/, "" ) m = new RegExp("^" + p.replace(/([\/\.])/g, "\\$1").replace(/\*|:[a-z\_\$][a-z0-9\_\$]*/g, "(.+?)") + "$") @r.push [v.toUpperCase(), o, m, f] A.call = (req, res) -> b = undefined req.setEncoding "utf8" b = "" req.on "data", (s) -> b += s req.on "end", -> ES = undefined a = undefined k = undefined req.body = b ES = WS.EventSource k = ES.isEventSource(req) a = new A(req, res, (if k then "EVENTSOURCE" else req.method)) if k a._x (h) -> s = undefined s = a.socket = new ES(req, res) h() s.addEventListener "close", -> s = null else a._x (h) -> r = undefined r = h() @render r if typeof r is "string" A.ws = (r, s, h) -> a = undefined a = new A(r, s, "WEBSOCKET") a._x (H) -> w = a.socket = new WS(r, s, h) H() w.addEventListener "close", -> w = null module.exports = A