Created
January 13, 2012 18:32
-
-
Save ashafa/1607945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns twansit.server.handler) | |
(defmacro respond-with | |
[& body] | |
(let [args (or (last (filter vector? body)) ['req 'res]) | |
res-code (or (last (filter integer? body)) 200) | |
headers (merge {:Content-Type "text/html; charset=UTF-8"} | |
(or (last (filter map? body)) {})) | |
output (or (last (filter list? body)) | |
(last (filter string? body)) "") | |
maybe-template? (if (list? output) true)] | |
`(fn [~@args] | |
(let [res# (second ~args)] | |
(.writeHeader res# ~res-code (utils/clj->js ~headers)) | |
(if (and ~maybe-template? (.render (first [~@output]))) | |
(let [template-fn# (nth [~@output] 0) | |
file# (nth [~@output] 1) | |
context# (nth [~@output] 2)] | |
(.render template-fn# file# | |
(utils/clj->js context#) | |
(utils/clj->js {}) | |
(fn [err# output#] | |
(if err# | |
(.end res# (str err#)) | |
(doto output# | |
(.addListener "data" #(.write res# %)) | |
(.addListener "end" #(. res# (end)))))))) ;; Offending line. Changing the sexpr to ...#(.end res# nil)... works. | |
(.end res# ~output)))))) | |
>>> javascript output for that line | |
b.addListener("end", function() { | |
return c.twansit.server.handler_SLASH_end() // Expecting 'return c.end()' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment