Last active
December 31, 2015 07:49
-
-
Save valotas/7956887 to your computer and use it in GitHub Desktop.
A way to override express' app.render function
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
app.use((req: express.Request, resp: express.Response, next?: Function) => { | |
var render = resp.render; | |
resp.render = (view: string, options?: any, fn?: any) => { | |
if ('function' == typeof options) { | |
fn = options; | |
options = {}; | |
} | |
render.call(resp, view, options, (err, html) => { | |
if (html) { | |
html = typo(html).typogrify(); | |
} | |
if (fn) { | |
fn(err, html); | |
} else { | |
if (err) next(err); | |
resp.send(html); | |
} | |
}); | |
}; | |
next(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment